summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorCVS to git conversion script <webmaster@postgresql.org>2002-06-20 20:29:55 +0000
committerCVS to git conversion script <webmaster@postgresql.org>2002-06-20 20:29:55 +0000
commit05dedace84ef8c93fea5309c3ac55f889011429b (patch)
tree4c7f513afbbc03060039a165d1770e11be711773 /src/backend/parser
parentd84fe82230c593f3dc5d7f427849b99d1efa8a0a (diff)
This commit was manufactured by cvs2git to create branch 'ecpg_big_bison'.
Sprout from master 2002-06-20 20:29:54 UTC Bruce Momjian <bruce@momjian.us> 'Update copyright to 2002.' Delete: COPYRIGHT GNUmakefile.in HISTORY INSTALL Makefile README aclocal.m4 config/ac_func_accept_argtypes.m4 config/c-compiler.m4 config/c-library.m4 config/config.guess config/config.sub config/cxx.m4 config/docbook.m4 config/general.m4 config/install-sh config/java.m4 config/libtool.m4 config/missing config/mkinstalldirs config/perl.m4 config/prep_buildtree config/programs.m4 config/python.m4 config/tcl.m4 configure configure.in contrib/Makefile contrib/README contrib/array/Makefile contrib/array/README.array_iterator contrib/array/array_iterator.c contrib/array/array_iterator.h contrib/array/array_iterator.sql.in contrib/btree_gist/Makefile contrib/btree_gist/README.btree_gist contrib/btree_gist/btree_gist.c contrib/btree_gist/btree_gist.sql.in contrib/btree_gist/data/test_btree.data contrib/btree_gist/data/test_btree_ts.data contrib/btree_gist/expected/btree_gist.out contrib/btree_gist/sql/btree_gist.sql contrib/chkpass/Makefile contrib/chkpass/README.chkpass contrib/chkpass/chkpass.c contrib/chkpass/chkpass.sql.in contrib/contrib-global.mk contrib/cube/Makefile contrib/cube/README.cube contrib/cube/buffer.c contrib/cube/buffer.h contrib/cube/cube.c contrib/cube/cube.sql.in contrib/cube/cubedata.h contrib/cube/cubeparse.y contrib/cube/cubescan.l contrib/cube/data/test_cube.data contrib/cube/expected/cube.out contrib/cube/sql/cube.sql contrib/dbase/Makefile contrib/dbase/README.dbf2pg contrib/dbase/dbf.c contrib/dbase/dbf.h contrib/dbase/dbf2pg.1 contrib/dbase/dbf2pg.c contrib/dbase/endian.c contrib/dblink/Makefile contrib/dblink/README.dblink contrib/dblink/dblink.c contrib/dblink/dblink.h contrib/dblink/dblink.sql.in contrib/dbsize/Makefile contrib/dbsize/README.dbsize contrib/dbsize/dbsize.c contrib/dbsize/dbsize.sql.in contrib/earthdistance/Makefile contrib/earthdistance/README.earthdistance contrib/earthdistance/earthdistance.c contrib/earthdistance/earthdistance.sql.in contrib/findoidjoins/Makefile contrib/findoidjoins/README.findoidjoins contrib/findoidjoins/findoidjoins.c contrib/findoidjoins/make_oidjoins_check contrib/fulltextindex/Makefile contrib/fulltextindex/README.fti contrib/fulltextindex/TODO contrib/fulltextindex/fti.c contrib/fulltextindex/fti.pl contrib/fulltextindex/fti.sql.in contrib/fulltextindex/timings.sh contrib/fuzzystrmatch/Makefile contrib/fuzzystrmatch/README.fuzzystrmatch contrib/fuzzystrmatch/README.soundex contrib/fuzzystrmatch/fuzzystrmatch.c contrib/fuzzystrmatch/fuzzystrmatch.h contrib/fuzzystrmatch/fuzzystrmatch.sql.in contrib/intagg/Makefile contrib/intagg/README.int_aggregate contrib/intagg/int_aggregate.c contrib/intagg/int_aggregate.sql.in contrib/intarray/Makefile contrib/intarray/README.intarray contrib/intarray/_int.c contrib/intarray/_int.sql.in contrib/intarray/bench/bench.pl contrib/intarray/bench/create_test.pl contrib/intarray/data/test__int.data contrib/intarray/expected/_int.out contrib/intarray/sql/_int.sql contrib/ipc_check/README contrib/ipc_check/ipc_check.pl contrib/isbn_issn/Makefile contrib/isbn_issn/README.isbn_issn contrib/isbn_issn/isbn_issn.c contrib/isbn_issn/isbn_issn.sql.in contrib/lo/Makefile contrib/lo/README.lo contrib/lo/lo.c contrib/lo/lo.sql.in contrib/lo/lo_drop.sql contrib/lo/lo_test.sql contrib/mSQL-interface/Makefile contrib/mSQL-interface/README.mpgsql contrib/mSQL-interface/mpgsql.c contrib/mac/README.mac contrib/mac/createoui contrib/mac/dropoui contrib/mac/ouiparse.awk contrib/mac/updateoui contrib/miscutil/Makefile contrib/miscutil/README.misc_utils contrib/miscutil/misc_utils.c contrib/miscutil/misc_utils.h contrib/miscutil/misc_utils.sql.in contrib/mysql/README contrib/mysql/my2pg.pl contrib/mysql/mysql2pgsql contrib/noupdate/Makefile contrib/noupdate/README.noup contrib/noupdate/noup.c contrib/noupdate/noup.sql.in contrib/oid2name/Makefile contrib/oid2name/README.oid2name contrib/oid2name/oid2name.c contrib/oracle/CHANGES contrib/oracle/Ora2Pg.pm contrib/oracle/README.ora2pg contrib/oracle/TODO contrib/oracle/ora2pg.html contrib/oracle/ora2pg.pl contrib/pg_controldata/Makefile contrib/pg_controldata/README.pg_controldata contrib/pg_controldata/pg_controldata.c contrib/pg_dumplo/Makefile contrib/pg_dumplo/README.pg_dumplo contrib/pg_dumplo/lo_export.c contrib/pg_dumplo/lo_import.c contrib/pg_dumplo/main.c contrib/pg_dumplo/pg_dumplo.h contrib/pg_dumplo/utils.c contrib/pg_logger/Makefile contrib/pg_logger/README.pg_logger contrib/pg_logger/pg_logger.c contrib/pg_resetxlog/Makefile contrib/pg_resetxlog/README.pg_resetxlog contrib/pg_resetxlog/pg_resetxlog.c contrib/pg_upgrade/README contrib/pg_upgrade/pg_upgrade contrib/pg_upgrade/pg_upgrade.1 contrib/pgbench/Makefile contrib/pgbench/README.pgbench contrib/pgbench/README.pgbench_jis contrib/pgbench/pgbench.c contrib/pgcrypto/API contrib/pgcrypto/Makefile contrib/pgcrypto/README.pgcrypto contrib/pgcrypto/blf.c contrib/pgcrypto/blf.h contrib/pgcrypto/crypt-blowfish.c contrib/pgcrypto/crypt-des.c contrib/pgcrypto/crypt-gensalt.c contrib/pgcrypto/crypt-md5.c contrib/pgcrypto/expected/blowfish.out contrib/pgcrypto/expected/crypt-blowfish.out contrib/pgcrypto/expected/crypt-des.out contrib/pgcrypto/expected/crypt-md5.out contrib/pgcrypto/expected/crypt-xdes.out contrib/pgcrypto/expected/hmac-md5.out contrib/pgcrypto/expected/hmac-sha1.out contrib/pgcrypto/expected/init.out contrib/pgcrypto/expected/md5.out contrib/pgcrypto/expected/rijndael.out contrib/pgcrypto/expected/sha1.out contrib/pgcrypto/internal.c contrib/pgcrypto/md5.c contrib/pgcrypto/md5.h contrib/pgcrypto/mhash.c contrib/pgcrypto/misc.c contrib/pgcrypto/openssl.c contrib/pgcrypto/pgcrypto.c contrib/pgcrypto/pgcrypto.h contrib/pgcrypto/pgcrypto.sql.in contrib/pgcrypto/px-crypt.c contrib/pgcrypto/px-crypt.h contrib/pgcrypto/px-hmac.c contrib/pgcrypto/px.c contrib/pgcrypto/px.h contrib/pgcrypto/random.c contrib/pgcrypto/rijndael.c contrib/pgcrypto/rijndael.h contrib/pgcrypto/rijndael.tbl contrib/pgcrypto/sha1.c contrib/pgcrypto/sha1.h contrib/pgcrypto/sql/blowfish.sql contrib/pgcrypto/sql/crypt-blowfish.sql contrib/pgcrypto/sql/crypt-des.sql contrib/pgcrypto/sql/crypt-md5.sql contrib/pgcrypto/sql/crypt-xdes.sql contrib/pgcrypto/sql/hmac-md5.sql contrib/pgcrypto/sql/hmac-sha1.sql contrib/pgcrypto/sql/init.sql contrib/pgcrypto/sql/md5.sql contrib/pgcrypto/sql/rijndael.sql contrib/pgcrypto/sql/sha1.sql contrib/pgstattuple/Makefile contrib/pgstattuple/README.pgstattuple contrib/pgstattuple/README.pgstattuple.euc_jp contrib/pgstattuple/pgstattuple.c contrib/pgstattuple/pgstattuple.sql.in contrib/retep/CHANGELOG contrib/retep/Implementation contrib/retep/Makefile contrib/retep/README contrib/retep/build.xml contrib/retep/data/cds.dtd contrib/retep/data/cds.xml contrib/retep/retep.jpx contrib/retep/uk/org/retep/dtu/DCollection.java contrib/retep/uk/org/retep/dtu/DConstants.java contrib/retep/uk/org/retep/dtu/DElement.java contrib/retep/uk/org/retep/dtu/DEnvironment.java contrib/retep/uk/org/retep/dtu/DModule.java contrib/retep/uk/org/retep/dtu/DModuleXML.java contrib/retep/uk/org/retep/dtu/DNode.java contrib/retep/uk/org/retep/dtu/DProcessor.java contrib/retep/uk/org/retep/dtu/DTransform.java contrib/retep/uk/org/retep/tools/Tool.java contrib/retep/uk/org/retep/tools.properties contrib/retep/uk/org/retep/util/ExceptionDialog.java contrib/retep/uk/org/retep/util/Globals.java contrib/retep/uk/org/retep/util/Logger.java contrib/retep/uk/org/retep/util/Main.java contrib/retep/uk/org/retep/util/StandaloneApp.java contrib/retep/uk/org/retep/util/hba/Editor.java contrib/retep/uk/org/retep/util/hba/Main.java contrib/retep/uk/org/retep/util/hba/Record.java contrib/retep/uk/org/retep/util/misc/IPAddress.java contrib/retep/uk/org/retep/util/misc/PropertiesIO.java contrib/retep/uk/org/retep/util/misc/WStringTokenizer.java contrib/retep/uk/org/retep/util/models/HBATableModel.java contrib/retep/uk/org/retep/util/models/PropertiesTableModel.java contrib/retep/uk/org/retep/util/proped/Main.java contrib/retep/uk/org/retep/util/proped/PropertyEditor.java contrib/retep/uk/org/retep/xml/core/XMLFactory.java contrib/retep/uk/org/retep/xml/core/XMLFactoryException.java contrib/retep/uk/org/retep/xml/jdbc/XMLDatabase.java contrib/retep/uk/org/retep/xml/jdbc/XMLResultSet.java contrib/retep/uk/org/retep/xml/parser/TagHandler.java contrib/retep/uk/org/retep/xml/parser/TagListener.java contrib/retep/uk/org/retep/xml/test/XMLExport.java contrib/rserv/ApplySnapshot.in contrib/rserv/CleanLog.in contrib/rserv/GetSyncID.in contrib/rserv/InitRservTest.in contrib/rserv/Makefile contrib/rserv/MasterAddTable.in contrib/rserv/MasterInit.in contrib/rserv/MasterSync.in contrib/rserv/PrepareSnapshot.in contrib/rserv/README.rserv contrib/rserv/RServ.pm contrib/rserv/Replicate.in contrib/rserv/RservTest.in contrib/rserv/SlaveAddTable.in contrib/rserv/SlaveInit.in contrib/rserv/master.sql.in contrib/rserv/regress.sh contrib/rserv/rserv.c contrib/rserv/slave.sql.in contrib/rtree_gist/Makefile contrib/rtree_gist/README.rtree_gist contrib/rtree_gist/bench/bench.pl contrib/rtree_gist/bench/create_test.pl contrib/rtree_gist/data/test_box.data contrib/rtree_gist/expected/rtree_gist.out contrib/rtree_gist/rtree_gist.c contrib/rtree_gist/rtree_gist.sql.in contrib/rtree_gist/sql/rtree_gist.sql contrib/seg/Makefile contrib/seg/README.seg contrib/seg/buffer.c contrib/seg/buffer.h contrib/seg/data/test_seg.data contrib/seg/expected/seg.out contrib/seg/seg-validate.pl contrib/seg/seg.c contrib/seg/seg.sql.in contrib/seg/segdata.h contrib/seg/segparse.y contrib/seg/segscan.l contrib/seg/sort-segments.pl contrib/seg/sql/seg.sql contrib/spi/Makefile contrib/spi/README.spi contrib/spi/autoinc.c contrib/spi/autoinc.example contrib/spi/autoinc.sql.in contrib/spi/insert_username.c contrib/spi/insert_username.example contrib/spi/insert_username.sql.in contrib/spi/moddatetime.c contrib/spi/moddatetime.example contrib/spi/moddatetime.sql.in contrib/spi/preprocessor/README.MAX contrib/spi/preprocessor/example.sql contrib/spi/preprocessor/step1.c contrib/spi/preprocessor/step1.e contrib/spi/preprocessor/step2.pl contrib/spi/refint.c contrib/spi/refint.example contrib/spi/refint.sql.in contrib/spi/timetravel.c contrib/spi/timetravel.example contrib/spi/timetravel.sql.in contrib/start-scripts/freebsd contrib/start-scripts/linux contrib/string/Makefile contrib/string/README.string_io contrib/string/string_io.c contrib/string/string_io.h contrib/string/string_io.sql.in contrib/tips/Makefile contrib/tips/README.apachelog contrib/tools/add-emacs-variables contrib/tools/find-sources contrib/tools/make-tags contrib/tsearch/Makefile contrib/tsearch/README.tsearch contrib/tsearch/crc32.c contrib/tsearch/crc32.h contrib/tsearch/data/test_tsearch.data contrib/tsearch/deflex.h contrib/tsearch/dict/porter_english.dct contrib/tsearch/dict/russian_stemming.dct contrib/tsearch/dict.h contrib/tsearch/expected/tsearch.out contrib/tsearch/gistidx.c contrib/tsearch/gistidx.h contrib/tsearch/makedict/makedict.pl contrib/tsearch/morph.c contrib/tsearch/morph.h contrib/tsearch/parser.h contrib/tsearch/parser.l contrib/tsearch/query.c contrib/tsearch/query.h contrib/tsearch/rewrite.c contrib/tsearch/rewrite.h contrib/tsearch/sql/tsearch.sql contrib/tsearch/tsearch.sql.in contrib/tsearch/txtidx.c contrib/tsearch/txtidx.h contrib/userlock/Makefile contrib/userlock/README.user_locks contrib/userlock/user_locks.c contrib/userlock/user_locks.h contrib/userlock/user_locks.sql.in contrib/vacuumlo/Makefile contrib/vacuumlo/README.vacuumlo contrib/vacuumlo/vacuumlo.c contrib/xml/Makefile contrib/xml/README contrib/xml/TODO contrib/xml/pgxml.c contrib/xml/pgxml.h contrib/xml/pgxml.source contrib/xml/pgxml_dom.c contrib/xml/pgxml_dom.source doc/FAQ doc/FAQ_AIX doc/FAQ_DEV doc/FAQ_HPUX doc/FAQ_IRIX doc/FAQ_MSWIN doc/FAQ_QNX4 doc/FAQ_SCO doc/FAQ_Solaris doc/FAQ_german doc/FAQ_japanese doc/FAQ_polish doc/FAQ_russian doc/KNOWN_BUGS doc/MISSING_FEATURES doc/Makefile doc/README.mb.big5 doc/README.mb.jp doc/TODO doc/TODO.detail/README doc/TODO.detail/atttypmod doc/TODO.detail/crossdb doc/TODO.detail/cursor doc/TODO.detail/drop doc/TODO.detail/exists doc/TODO.detail/foreign doc/TODO.detail/fsync doc/TODO.detail/inheritance doc/TODO.detail/java doc/TODO.detail/mmap doc/TODO.detail/namedatalen doc/TODO.detail/optimizer doc/TODO.detail/performance doc/TODO.detail/persistent doc/TODO.detail/pool doc/TODO.detail/prepare doc/TODO.detail/privileges doc/TODO.detail/replication doc/TODO.detail/schema doc/TODO.detail/tablespaces doc/TODO.detail/thread doc/TODO.detail/transactions doc/TODO.detail/typeconv doc/TODO.detail/update doc/TODO.detail/vacuum doc/TODO.detail/view doc/TODO.detail/win32 doc/TODO.detail/yacc doc/bug.template doc/src/FAQ/FAQ.html doc/src/FAQ/FAQ_DEV.html doc/src/FAQ/FAQ_german.html doc/src/FAQ/FAQ_japanese.html doc/src/FAQ/FAQ_polish.html doc/src/FAQ/FAQ_russian.html doc/src/Makefile doc/src/graphics/catalogs.ag doc/src/graphics/catalogs.cgm doc/src/graphics/catalogs.gif doc/src/graphics/catalogs.ps doc/src/graphics/clientserver.ag doc/src/graphics/clientserver.gif doc/src/graphics/connections.ag doc/src/graphics/connections.gif doc/src/sgml/Makefile doc/src/sgml/admin.sgml doc/src/sgml/advanced.sgml doc/src/sgml/arch-dev.sgml doc/src/sgml/arch-pg.sgml doc/src/sgml/array.sgml doc/src/sgml/backup.sgml doc/src/sgml/biblio.sgml doc/src/sgml/bki.sgml doc/src/sgml/book-decl.sgml doc/src/sgml/catalogs.sgml doc/src/sgml/charset.sgml doc/src/sgml/client-auth.sgml doc/src/sgml/compiler.sgml doc/src/sgml/contacts.sgml doc/src/sgml/cvs.sgml doc/src/sgml/datatype.sgml doc/src/sgml/datetime.sgml doc/src/sgml/developer.sgml doc/src/sgml/dfunc.sgml doc/src/sgml/diskusage.sgml doc/src/sgml/docguide.sgml doc/src/sgml/ecpg.sgml doc/src/sgml/extend.sgml doc/src/sgml/features.sgml doc/src/sgml/filelist.sgml doc/src/sgml/fixrtf doc/src/sgml/func-ref.sgml doc/src/sgml/func.sgml doc/src/sgml/geqo.sgml doc/src/sgml/gist.sgml doc/src/sgml/history.sgml doc/src/sgml/indexcost.sgml doc/src/sgml/indices.sgml doc/src/sgml/info.sgml doc/src/sgml/inherit.sgml doc/src/sgml/install-win32.sgml doc/src/sgml/installation.sgml doc/src/sgml/intro.sgml doc/src/sgml/jdbc.sgml doc/src/sgml/keywords.sgml doc/src/sgml/legal.sgml doc/src/sgml/libpgeasy.sgml doc/src/sgml/libpgtcl.sgml doc/src/sgml/libpq++.sgml doc/src/sgml/libpq.sgml doc/src/sgml/lobj.sgml doc/src/sgml/maintenance.sgml doc/src/sgml/manage-ag.sgml doc/src/sgml/manage.sgml doc/src/sgml/monitoring.sgml doc/src/sgml/mvcc.sgml doc/src/sgml/nls.sgml doc/src/sgml/notation.sgml doc/src/sgml/odbc.sgml doc/src/sgml/page.sgml doc/src/sgml/perform.sgml doc/src/sgml/plperl.sgml doc/src/sgml/plpython.sgml doc/src/sgml/plsql.sgml doc/src/sgml/pltcl.sgml doc/src/sgml/postgres.sgml doc/src/sgml/problems.sgml doc/src/sgml/programmer.sgml doc/src/sgml/protocol.sgml doc/src/sgml/pygresql.sgml doc/src/sgml/queries.sgml doc/src/sgml/query.sgml doc/src/sgml/recovery.sgml doc/src/sgml/ref/abort.sgml doc/src/sgml/ref/allfiles.sgml doc/src/sgml/ref/alter_database.sgml doc/src/sgml/ref/alter_group.sgml doc/src/sgml/ref/alter_table.sgml doc/src/sgml/ref/alter_trigger.sgml doc/src/sgml/ref/alter_user.sgml doc/src/sgml/ref/analyze.sgml doc/src/sgml/ref/begin.sgml doc/src/sgml/ref/checkpoint.sgml doc/src/sgml/ref/close.sgml doc/src/sgml/ref/cluster.sgml doc/src/sgml/ref/comment.sgml doc/src/sgml/ref/commit.sgml doc/src/sgml/ref/copy.sgml doc/src/sgml/ref/create_aggregate.sgml doc/src/sgml/ref/create_constraint.sgml doc/src/sgml/ref/create_database.sgml doc/src/sgml/ref/create_domain.sgml doc/src/sgml/ref/create_function.sgml doc/src/sgml/ref/create_group.sgml doc/src/sgml/ref/create_index.sgml doc/src/sgml/ref/create_language.sgml doc/src/sgml/ref/create_operator.sgml doc/src/sgml/ref/create_rule.sgml doc/src/sgml/ref/create_schema.sgml doc/src/sgml/ref/create_sequence.sgml doc/src/sgml/ref/create_table.sgml doc/src/sgml/ref/create_table_as.sgml doc/src/sgml/ref/create_trigger.sgml doc/src/sgml/ref/create_type.sgml doc/src/sgml/ref/create_user.sgml doc/src/sgml/ref/create_view.sgml doc/src/sgml/ref/createdb.sgml doc/src/sgml/ref/createlang.sgml doc/src/sgml/ref/createuser.sgml doc/src/sgml/ref/current_date.sgml doc/src/sgml/ref/current_time.sgml doc/src/sgml/ref/current_timestamp.sgml doc/src/sgml/ref/current_user.sgml doc/src/sgml/ref/declare.sgml doc/src/sgml/ref/delete.sgml doc/src/sgml/ref/drop_aggregate.sgml doc/src/sgml/ref/drop_database.sgml doc/src/sgml/ref/drop_domain.sgml doc/src/sgml/ref/drop_function.sgml doc/src/sgml/ref/drop_group.sgml doc/src/sgml/ref/drop_index.sgml doc/src/sgml/ref/drop_language.sgml doc/src/sgml/ref/drop_operator.sgml doc/src/sgml/ref/drop_rule.sgml doc/src/sgml/ref/drop_sequence.sgml doc/src/sgml/ref/drop_table.sgml doc/src/sgml/ref/drop_trigger.sgml doc/src/sgml/ref/drop_type.sgml doc/src/sgml/ref/drop_user.sgml doc/src/sgml/ref/drop_view.sgml doc/src/sgml/ref/dropdb.sgml doc/src/sgml/ref/droplang.sgml doc/src/sgml/ref/dropuser.sgml doc/src/sgml/ref/ecpg-ref.sgml doc/src/sgml/ref/end.sgml doc/src/sgml/ref/explain.sgml doc/src/sgml/ref/fetch.sgml doc/src/sgml/ref/grant.sgml doc/src/sgml/ref/initdb.sgml doc/src/sgml/ref/initlocation.sgml doc/src/sgml/ref/insert.sgml doc/src/sgml/ref/ipcclean.sgml doc/src/sgml/ref/listen.sgml doc/src/sgml/ref/load.sgml doc/src/sgml/ref/lock.sgml doc/src/sgml/ref/move.sgml doc/src/sgml/ref/notify.sgml doc/src/sgml/ref/pg_config-ref.sgml doc/src/sgml/ref/pg_ctl-ref.sgml doc/src/sgml/ref/pg_dump.sgml doc/src/sgml/ref/pg_dumpall.sgml doc/src/sgml/ref/pg_restore.sgml doc/src/sgml/ref/pgaccess-ref.sgml doc/src/sgml/ref/pgtclsh.sgml doc/src/sgml/ref/pgtksh.sgml doc/src/sgml/ref/postgres-ref.sgml doc/src/sgml/ref/postmaster.sgml doc/src/sgml/ref/psql-ref.sgml doc/src/sgml/ref/reindex.sgml doc/src/sgml/ref/reset.sgml doc/src/sgml/ref/revoke.sgml doc/src/sgml/ref/rollback.sgml doc/src/sgml/ref/select.sgml doc/src/sgml/ref/select_into.sgml doc/src/sgml/ref/set.sgml doc/src/sgml/ref/set_constraints.sgml doc/src/sgml/ref/set_session_auth.sgml doc/src/sgml/ref/set_transaction.sgml doc/src/sgml/ref/show.sgml doc/src/sgml/ref/truncate.sgml doc/src/sgml/ref/unlisten.sgml doc/src/sgml/ref/update.sgml doc/src/sgml/ref/vacuum.sgml doc/src/sgml/ref/vacuumdb.sgml doc/src/sgml/refentry.sgml doc/src/sgml/reference.ced doc/src/sgml/reference.sgml doc/src/sgml/regress.sgml doc/src/sgml/release.sgml doc/src/sgml/rules.sgml doc/src/sgml/runtime.sgml doc/src/sgml/sources.sgml doc/src/sgml/spi.sgml doc/src/sgml/sql.sgml doc/src/sgml/standalone-install.sgml doc/src/sgml/start.sgml doc/src/sgml/stylesheet.css doc/src/sgml/stylesheet.dsl doc/src/sgml/syntax.sgml doc/src/sgml/trigger.sgml doc/src/sgml/tutorial.sgml doc/src/sgml/typeconv.sgml doc/src/sgml/user-manag.sgml doc/src/sgml/user.sgml doc/src/sgml/version.sgml doc/src/sgml/wal.sgml doc/src/sgml/xaggr.sgml doc/src/sgml/xfunc.sgml doc/src/sgml/xindex.sgml doc/src/sgml/xoper.sgml doc/src/sgml/xplang.sgml doc/src/sgml/xtypes.sgml doc/src/sgml/y2k.sgml register.txt src/DEVELOPERS src/Makefile src/Makefile.global.in src/Makefile.shlib src/backend/Makefile src/backend/access/Makefile src/backend/access/common/Makefile src/backend/access/common/heaptuple.c src/backend/access/common/indextuple.c src/backend/access/common/indexvalid.c src/backend/access/common/printtup.c src/backend/access/common/scankey.c src/backend/access/common/tupdesc.c src/backend/access/gist/Makefile src/backend/access/gist/gist.c src/backend/access/gist/gistget.c src/backend/access/gist/gistscan.c src/backend/access/gist/giststrat.c src/backend/access/hash/Makefile src/backend/access/hash/hash.c src/backend/access/hash/hashfunc.c src/backend/access/hash/hashinsert.c src/backend/access/hash/hashovfl.c src/backend/access/hash/hashpage.c src/backend/access/hash/hashscan.c src/backend/access/hash/hashsearch.c src/backend/access/hash/hashstrat.c src/backend/access/hash/hashutil.c src/backend/access/heap/Makefile src/backend/access/heap/heapam.c src/backend/access/heap/hio.c src/backend/access/heap/tuptoaster.c src/backend/access/index/Makefile src/backend/access/index/genam.c src/backend/access/index/indexam.c src/backend/access/index/istrat.c src/backend/access/nbtree/Makefile src/backend/access/nbtree/README src/backend/access/nbtree/nbtcompare.c src/backend/access/nbtree/nbtinsert.c src/backend/access/nbtree/nbtpage.c src/backend/access/nbtree/nbtree.c src/backend/access/nbtree/nbtsearch.c src/backend/access/nbtree/nbtsort.c src/backend/access/nbtree/nbtstrat.c src/backend/access/nbtree/nbtutils.c src/backend/access/rtree/Makefile src/backend/access/rtree/rtget.c src/backend/access/rtree/rtproc.c src/backend/access/rtree/rtree.c src/backend/access/rtree/rtscan.c src/backend/access/rtree/rtstrat.c src/backend/access/transam/Makefile src/backend/access/transam/clog.c src/backend/access/transam/rmgr.c src/backend/access/transam/transam.c src/backend/access/transam/varsup.c src/backend/access/transam/xact.c src/backend/access/transam/xid.c src/backend/access/transam/xlog.c src/backend/access/transam/xlogutils.c src/backend/bootstrap/.cvsignore src/backend/bootstrap/Makefile src/backend/bootstrap/bootparse.y src/backend/bootstrap/bootscanner.l src/backend/bootstrap/bootstrap.c src/backend/catalog/Makefile src/backend/catalog/README src/backend/catalog/aclchk.c src/backend/catalog/catalog.c src/backend/catalog/genbki.sh src/backend/catalog/heap.c src/backend/catalog/index.c src/backend/catalog/indexing.c src/backend/catalog/namespace.c src/backend/catalog/pg_aggregate.c src/backend/catalog/pg_largeobject.c src/backend/catalog/pg_namespace.c src/backend/catalog/pg_operator.c src/backend/catalog/pg_proc.c src/backend/catalog/pg_type.c src/backend/commands/Makefile src/backend/commands/_deadcode/recipe.c src/backend/commands/_deadcode/recipe.h src/backend/commands/_deadcode/version.c src/backend/commands/aggregatecmds.c src/backend/commands/analyze.c src/backend/commands/async.c src/backend/commands/cluster.c src/backend/commands/comment.c src/backend/commands/copy.c src/backend/commands/dbcommands.c src/backend/commands/define.c src/backend/commands/explain.c src/backend/commands/functioncmds.c src/backend/commands/indexcmds.c src/backend/commands/lockcmds.c src/backend/commands/operatorcmds.c src/backend/commands/portalcmds.c src/backend/commands/proclang.c src/backend/commands/schemacmds.c src/backend/commands/sequence.c src/backend/commands/tablecmds.c src/backend/commands/trigger.c src/backend/commands/typecmds.c src/backend/commands/user.c src/backend/commands/vacuum.c src/backend/commands/vacuumlazy.c src/backend/commands/variable.c src/backend/commands/view.c src/backend/executor/Makefile src/backend/executor/README src/backend/executor/_deadcode/nodeTee.c src/backend/executor/execAmi.c src/backend/executor/execJunk.c src/backend/executor/execMain.c src/backend/executor/execProcnode.c src/backend/executor/execQual.c src/backend/executor/execScan.c src/backend/executor/execTuples.c src/backend/executor/execUtils.c src/backend/executor/functions.c src/backend/executor/instrument.c src/backend/executor/nodeAgg.c src/backend/executor/nodeAppend.c src/backend/executor/nodeFunctionscan.c src/backend/executor/nodeGroup.c src/backend/executor/nodeHash.c src/backend/executor/nodeHashjoin.c src/backend/executor/nodeIndexscan.c src/backend/executor/nodeLimit.c src/backend/executor/nodeMaterial.c src/backend/executor/nodeMergejoin.c src/backend/executor/nodeNestloop.c src/backend/executor/nodeResult.c src/backend/executor/nodeSeqscan.c src/backend/executor/nodeSetOp.c src/backend/executor/nodeSort.c src/backend/executor/nodeSubplan.c src/backend/executor/nodeSubqueryscan.c src/backend/executor/nodeTidscan.c src/backend/executor/nodeUnique.c src/backend/executor/spi.c src/backend/lib/Makefile src/backend/lib/bit.c src/backend/lib/dllist.c src/backend/lib/lispsort.c src/backend/lib/stringinfo.c src/backend/libpq/Makefile src/backend/libpq/README.SSL src/backend/libpq/auth.c src/backend/libpq/be-fsstubs.c src/backend/libpq/be-secure.c src/backend/libpq/crypt.c src/backend/libpq/hba.c src/backend/libpq/md5.c src/backend/libpq/pg_hba.conf.sample src/backend/libpq/pg_ident.conf.sample src/backend/libpq/pqcomm.c src/backend/libpq/pqformat.c src/backend/libpq/pqsignal.c src/backend/main/Makefile src/backend/main/main.c src/backend/nodes/Makefile src/backend/nodes/README src/backend/nodes/copyfuncs.c src/backend/nodes/equalfuncs.c src/backend/nodes/list.c src/backend/nodes/makefuncs.c src/backend/nodes/nodeFuncs.c src/backend/nodes/nodes.c src/backend/nodes/outfuncs.c src/backend/nodes/print.c src/backend/nodes/read.c src/backend/nodes/readfuncs.c src/backend/optimizer/Makefile src/backend/optimizer/README src/backend/optimizer/geqo/Makefile src/backend/optimizer/geqo/geqo_copy.c src/backend/optimizer/geqo/geqo_cx.c src/backend/optimizer/geqo/geqo_erx.c src/backend/optimizer/geqo/geqo_eval.c src/backend/optimizer/geqo/geqo_main.c src/backend/optimizer/geqo/geqo_misc.c src/backend/optimizer/geqo/geqo_mutation.c src/backend/optimizer/geqo/geqo_ox1.c src/backend/optimizer/geqo/geqo_ox2.c src/backend/optimizer/geqo/geqo_pmx.c src/backend/optimizer/geqo/geqo_pool.c src/backend/optimizer/geqo/geqo_px.c src/backend/optimizer/geqo/geqo_recombination.c src/backend/optimizer/geqo/geqo_selection.c src/backend/optimizer/path/Makefile src/backend/optimizer/path/_deadcode/predmig.c src/backend/optimizer/path/_deadcode/xfunc.c src/backend/optimizer/path/allpaths.c src/backend/optimizer/path/clausesel.c src/backend/optimizer/path/costsize.c src/backend/optimizer/path/indxpath.c src/backend/optimizer/path/joinpath.c src/backend/optimizer/path/joinrels.c src/backend/optimizer/path/orindxpath.c src/backend/optimizer/path/pathkeys.c src/backend/optimizer/path/tidpath.c src/backend/optimizer/plan/Makefile src/backend/optimizer/plan/README src/backend/optimizer/plan/createplan.c src/backend/optimizer/plan/initsplan.c src/backend/optimizer/plan/planmain.c src/backend/optimizer/plan/planner.c src/backend/optimizer/plan/setrefs.c src/backend/optimizer/plan/subselect.c src/backend/optimizer/prep/Makefile src/backend/optimizer/prep/_deadcode/prepkeyset.c src/backend/optimizer/prep/prepqual.c src/backend/optimizer/prep/preptlist.c src/backend/optimizer/prep/prepunion.c src/backend/optimizer/util/Makefile src/backend/optimizer/util/clauses.c src/backend/optimizer/util/joininfo.c src/backend/optimizer/util/pathnode.c src/backend/optimizer/util/plancat.c src/backend/optimizer/util/relnode.c src/backend/optimizer/util/restrictinfo.c src/backend/optimizer/util/tlist.c src/backend/optimizer/util/var.c src/backend/parser/.cvsignore src/backend/parser/Makefile src/backend/parser/README src/backend/parser/analyze.c src/backend/parser/gram.y src/backend/parser/keywords.c src/backend/parser/parse_agg.c src/backend/parser/parse_clause.c src/backend/parser/parse_coerce.c src/backend/parser/parse_expr.c src/backend/parser/parse_func.c src/backend/parser/parse_node.c src/backend/parser/parse_oper.c src/backend/parser/parse_relation.c src/backend/parser/parse_target.c src/backend/parser/parse_type.c src/backend/parser/parser.c src/backend/parser/scan.l src/backend/parser/scansup.c src/backend/po/Makefile src/backend/po/cs.po src/backend/po/de.po src/backend/po/hu.po src/backend/po/nls.mk src/backend/po/ru.po src/backend/po/zh_CN.po src/backend/po/zh_TW.po src/backend/port/Makefile src/backend/port/aix/mkldexport.sh src/backend/port/beos/Makefile src/backend/port/beos/sem.c src/backend/port/beos/shm.c src/backend/port/beos/support.c src/backend/port/darwin/Makefile src/backend/port/darwin/README src/backend/port/darwin/system.c src/backend/port/dynloader/README.dlfcn.aix src/backend/port/dynloader/aix.c src/backend/port/dynloader/aix.h src/backend/port/dynloader/beos.c src/backend/port/dynloader/beos.h src/backend/port/dynloader/bsdi.c src/backend/port/dynloader/bsdi.h src/backend/port/dynloader/darwin.c src/backend/port/dynloader/darwin.h src/backend/port/dynloader/dgux.c src/backend/port/dynloader/dgux.h src/backend/port/dynloader/freebsd.c src/backend/port/dynloader/freebsd.h src/backend/port/dynloader/hpux.c src/backend/port/dynloader/hpux.h src/backend/port/dynloader/irix5.c src/backend/port/dynloader/irix5.h src/backend/port/dynloader/linux.c src/backend/port/dynloader/linux.h src/backend/port/dynloader/netbsd.c src/backend/port/dynloader/netbsd.h src/backend/port/dynloader/nextstep.c src/backend/port/dynloader/nextstep.h src/backend/port/dynloader/openbsd.c src/backend/port/dynloader/openbsd.h src/backend/port/dynloader/osf.c src/backend/port/dynloader/osf.h src/backend/port/dynloader/qnx4.c src/backend/port/dynloader/qnx4.h src/backend/port/dynloader/sco.c src/backend/port/dynloader/sco.h src/backend/port/dynloader/solaris.c src/backend/port/dynloader/solaris.h src/backend/port/dynloader/sunos4.c src/backend/port/dynloader/sunos4.h src/backend/port/dynloader/svr4.c src/backend/port/dynloader/svr4.h src/backend/port/dynloader/ultrix4.c src/backend/port/dynloader/ultrix4.h src/backend/port/dynloader/univel.c src/backend/port/dynloader/univel.h src/backend/port/dynloader/unixware.c src/backend/port/dynloader/unixware.h src/backend/port/dynloader/win.c src/backend/port/dynloader/win.h src/backend/port/gethostname.c src/backend/port/getrusage.c src/backend/port/hpux/tas.c.template src/backend/port/inet_aton.c src/backend/port/inet_aton.h src/backend/port/ipc_test.c src/backend/port/isinf.c src/backend/port/memcmp.c src/backend/port/nextstep/Makefile src/backend/port/nextstep/port.c src/backend/port/posix_sema.c src/backend/port/qnx4/Makefile src/backend/port/qnx4/ipc.h src/backend/port/qnx4/isnan.c src/backend/port/qnx4/rint.c src/backend/port/qnx4/sem.c src/backend/port/qnx4/sem.h src/backend/port/qnx4/shm.c src/backend/port/qnx4/shm.h src/backend/port/qnx4/tstrint.c src/backend/port/qnx4/tstsem.c src/backend/port/qnx4/tstshm.c src/backend/port/random.c src/backend/port/snprintf.c src/backend/port/srandom.c src/backend/port/strcasecmp.c src/backend/port/strerror.c src/backend/port/strtol.c src/backend/port/strtoul.c src/backend/port/sunos4/Makefile src/backend/port/sunos4/float.h src/backend/port/sysv_sema.c src/backend/port/sysv_shmem.c src/backend/port/tas/dummy.s src/backend/port/tas/hpux.s src/backend/port/tas/solaris_i386.s src/backend/port/tas/solaris_sparc.s src/backend/postmaster/Makefile src/backend/postmaster/pgstat.c src/backend/postmaster/postmaster.c src/backend/regex/COPYRIGHT src/backend/regex/Makefile src/backend/regex/WHATSNEW src/backend/regex/engine.c src/backend/regex/re_format.7 src/backend/regex/regcomp.c src/backend/regex/regerror.c src/backend/regex/regex.3 src/backend/regex/regexec.c src/backend/regex/regfree.c src/backend/regex/retest.c src/backend/rewrite/Makefile src/backend/rewrite/rewriteDefine.c src/backend/rewrite/rewriteHandler.c src/backend/rewrite/rewriteManip.c src/backend/rewrite/rewriteRemove.c src/backend/rewrite/rewriteSupport.c src/backend/storage/Makefile src/backend/storage/buffer/Makefile src/backend/storage/buffer/README src/backend/storage/buffer/buf_init.c src/backend/storage/buffer/buf_table.c src/backend/storage/buffer/bufmgr.c src/backend/storage/buffer/freelist.c src/backend/storage/buffer/localbuf.c src/backend/storage/file/Makefile src/backend/storage/file/buffile.c src/backend/storage/file/fd.c src/backend/storage/freespace/Makefile src/backend/storage/freespace/freespace.c src/backend/storage/ipc/Makefile src/backend/storage/ipc/README src/backend/storage/ipc/ipc.c src/backend/storage/ipc/ipci.c src/backend/storage/ipc/pmsignal.c src/backend/storage/ipc/shmem.c src/backend/storage/ipc/shmqueue.c src/backend/storage/ipc/sinval.c src/backend/storage/ipc/sinvaladt.c src/backend/storage/large_object/Makefile src/backend/storage/large_object/inv_api.c src/backend/storage/lmgr/Makefile src/backend/storage/lmgr/README src/backend/storage/lmgr/deadlock.c src/backend/storage/lmgr/lmgr.c src/backend/storage/lmgr/lock.c src/backend/storage/lmgr/lwlock.c src/backend/storage/lmgr/proc.c src/backend/storage/lmgr/s_lock.c src/backend/storage/lmgr/spin.c src/backend/storage/page/Makefile src/backend/storage/page/bufpage.c src/backend/storage/page/itemptr.c src/backend/storage/smgr/Makefile src/backend/storage/smgr/README src/backend/storage/smgr/md.c src/backend/storage/smgr/mm.c src/backend/storage/smgr/smgr.c src/backend/storage/smgr/smgrtype.c src/backend/tcop/Makefile src/backend/tcop/dest.c src/backend/tcop/fastpath.c src/backend/tcop/postgres.c src/backend/tcop/pquery.c src/backend/tcop/utility.c src/backend/tioga/Arr_TgRecipe.h src/backend/tioga/Makefile src/backend/tioga/Varray.c src/backend/tioga/Varray.h src/backend/tioga/tgRecipe.c src/backend/tioga/tgRecipe.h src/backend/utils/.cvsignore src/backend/utils/Gen_fmgrtab.sh src/backend/utils/Makefile src/backend/utils/adt/Makefile src/backend/utils/adt/acl.c src/backend/utils/adt/arrayfuncs.c src/backend/utils/adt/arrayutils.c src/backend/utils/adt/ascii.c src/backend/utils/adt/bool.c src/backend/utils/adt/cash.c src/backend/utils/adt/char.c src/backend/utils/adt/date.c src/backend/utils/adt/datetime.c src/backend/utils/adt/datum.c src/backend/utils/adt/encode.c src/backend/utils/adt/float.c src/backend/utils/adt/format_type.c src/backend/utils/adt/formatting.c src/backend/utils/adt/geo_ops.c src/backend/utils/adt/geo_selfuncs.c src/backend/utils/adt/inet_net_ntop.c src/backend/utils/adt/inet_net_pton.c src/backend/utils/adt/int.c src/backend/utils/adt/int8.c src/backend/utils/adt/like.c src/backend/utils/adt/like_match.c src/backend/utils/adt/mac.c src/backend/utils/adt/misc.c src/backend/utils/adt/nabstime.c src/backend/utils/adt/name.c src/backend/utils/adt/network.c src/backend/utils/adt/not_in.c src/backend/utils/adt/numeric.c src/backend/utils/adt/numutils.c src/backend/utils/adt/oid.c src/backend/utils/adt/oracle_compat.c src/backend/utils/adt/pg_locale.c src/backend/utils/adt/pg_lzcompress.c src/backend/utils/adt/pgstatfuncs.c src/backend/utils/adt/quote.c src/backend/utils/adt/regexp.c src/backend/utils/adt/regproc.c src/backend/utils/adt/ri_triggers.c src/backend/utils/adt/ruleutils.c src/backend/utils/adt/selfuncs.c src/backend/utils/adt/sets.c src/backend/utils/adt/tid.c src/backend/utils/adt/timestamp.c src/backend/utils/adt/varbit.c src/backend/utils/adt/varchar.c src/backend/utils/adt/varlena.c src/backend/utils/adt/version.c src/backend/utils/cache/Makefile src/backend/utils/cache/catcache.c src/backend/utils/cache/fcache.c src/backend/utils/cache/inval.c src/backend/utils/cache/lsyscache.c src/backend/utils/cache/relcache.c src/backend/utils/cache/syscache.c src/backend/utils/error/Makefile src/backend/utils/error/assert.c src/backend/utils/error/elog.c src/backend/utils/error/exc.c src/backend/utils/error/excabort.c src/backend/utils/error/excid.c src/backend/utils/error/format.c src/backend/utils/fmgr/Makefile src/backend/utils/fmgr/README src/backend/utils/fmgr/dfmgr.c src/backend/utils/fmgr/fmgr.c src/backend/utils/hash/Makefile src/backend/utils/hash/dynahash.c src/backend/utils/hash/hashfn.c src/backend/utils/hash/pg_crc.c src/backend/utils/init/Makefile src/backend/utils/init/findbe.c src/backend/utils/init/globals.c src/backend/utils/init/miscinit.c src/backend/utils/init/postinit.c src/backend/utils/mb/Makefile src/backend/utils/mb/README src/backend/utils/mb/Unicode/ISO10646-GB18030.TXT src/backend/utils/mb/Unicode/Makefile src/backend/utils/mb/Unicode/UCS_to_8859.pl src/backend/utils/mb/Unicode/UCS_to_BIG5.pl src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl src/backend/utils/mb/Unicode/UCS_to_GB18030.pl src/backend/utils/mb/Unicode/UCS_to_GBK.pl src/backend/utils/mb/Unicode/UCS_to_JOHAB.pl src/backend/utils/mb/Unicode/UCS_to_SJIS.pl src/backend/utils/mb/Unicode/UCS_to_UHC.pl src/backend/utils/mb/Unicode/UCS_to_WIN874.pl src/backend/utils/mb/Unicode/UCS_to_WINX.pl src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl src/backend/utils/mb/Unicode/alt_to_utf8.map src/backend/utils/mb/Unicode/big5_to_utf8.map src/backend/utils/mb/Unicode/euc_cn_to_utf8.map src/backend/utils/mb/Unicode/euc_jp_to_utf8.map src/backend/utils/mb/Unicode/euc_kr_to_utf8.map src/backend/utils/mb/Unicode/euc_tw_to_utf8.map src/backend/utils/mb/Unicode/gb18030_to_utf8.map src/backend/utils/mb/Unicode/gbk_to_utf8.map src/backend/utils/mb/Unicode/iso8859_10_to_utf8.map src/backend/utils/mb/Unicode/iso8859_13_to_utf8.map src/backend/utils/mb/Unicode/iso8859_14_to_utf8.map src/backend/utils/mb/Unicode/iso8859_15_to_utf8.map src/backend/utils/mb/Unicode/iso8859_16_to_utf8.map src/backend/utils/mb/Unicode/iso8859_2_to_utf8.map src/backend/utils/mb/Unicode/iso8859_3_to_utf8.map src/backend/utils/mb/Unicode/iso8859_4_to_utf8.map src/backend/utils/mb/Unicode/iso8859_5_to_utf8.map src/backend/utils/mb/Unicode/iso8859_6_to_utf8.map src/backend/utils/mb/Unicode/iso8859_7_to_utf8.map src/backend/utils/mb/Unicode/iso8859_8_to_utf8.map src/backend/utils/mb/Unicode/iso8859_9_to_utf8.map src/backend/utils/mb/Unicode/johab_to_utf8.map src/backend/utils/mb/Unicode/koi8r_to_utf8.map src/backend/utils/mb/Unicode/sjis_to_utf8.map src/backend/utils/mb/Unicode/tcvn_to_utf8.map src/backend/utils/mb/Unicode/ucs2utf.pl src/backend/utils/mb/Unicode/uhc_to_utf8.map src/backend/utils/mb/Unicode/utf8_to_alt.map src/backend/utils/mb/Unicode/utf8_to_big5.map src/backend/utils/mb/Unicode/utf8_to_euc_cn.map src/backend/utils/mb/Unicode/utf8_to_euc_jp.map src/backend/utils/mb/Unicode/utf8_to_euc_kr.map src/backend/utils/mb/Unicode/utf8_to_euc_tw.map src/backend/utils/mb/Unicode/utf8_to_gb18030.map src/backend/utils/mb/Unicode/utf8_to_gbk.map src/backend/utils/mb/Unicode/utf8_to_iso8859_10.map src/backend/utils/mb/Unicode/utf8_to_iso8859_13.map src/backend/utils/mb/Unicode/utf8_to_iso8859_14.map src/backend/utils/mb/Unicode/utf8_to_iso8859_15.map src/backend/utils/mb/Unicode/utf8_to_iso8859_16.map src/backend/utils/mb/Unicode/utf8_to_iso8859_2.map src/backend/utils/mb/Unicode/utf8_to_iso8859_3.map src/backend/utils/mb/Unicode/utf8_to_iso8859_4.map src/backend/utils/mb/Unicode/utf8_to_iso8859_5.map src/backend/utils/mb/Unicode/utf8_to_iso8859_6.map src/backend/utils/mb/Unicode/utf8_to_iso8859_7.map src/backend/utils/mb/Unicode/utf8_to_iso8859_8.map src/backend/utils/mb/Unicode/utf8_to_iso8859_9.map src/backend/utils/mb/Unicode/utf8_to_johab.map src/backend/utils/mb/Unicode/utf8_to_koi8r.map src/backend/utils/mb/Unicode/utf8_to_sjis.map src/backend/utils/mb/Unicode/utf8_to_tcvn.map src/backend/utils/mb/Unicode/utf8_to_uhc.map src/backend/utils/mb/Unicode/utf8_to_win1250.map src/backend/utils/mb/Unicode/utf8_to_win1251.map src/backend/utils/mb/Unicode/utf8_to_win1256.map src/backend/utils/mb/Unicode/utf8_to_win874.map src/backend/utils/mb/Unicode/win1250_to_utf8.map src/backend/utils/mb/Unicode/win1251_to_utf8.map src/backend/utils/mb/Unicode/win1256_to_utf8.map src/backend/utils/mb/Unicode/win874_to_utf8.map src/backend/utils/mb/alt.c src/backend/utils/mb/big5.c src/backend/utils/mb/conv.c src/backend/utils/mb/encnames.c src/backend/utils/mb/iso.c src/backend/utils/mb/mbutils.c src/backend/utils/mb/sjis.map src/backend/utils/mb/wchar.c src/backend/utils/mb/win.c src/backend/utils/mb/win1251.c src/backend/utils/mb/wstrcmp.c src/backend/utils/mb/wstrncmp.c src/backend/utils/misc/.cvsignore src/backend/utils/misc/Makefile src/backend/utils/misc/README src/backend/utils/misc/database.c src/backend/utils/misc/guc-file.l src/backend/utils/misc/guc.c src/backend/utils/misc/postgresql.conf.sample src/backend/utils/misc/ps_status.c src/backend/utils/misc/superuser.c src/backend/utils/mmgr/Makefile src/backend/utils/mmgr/README src/backend/utils/mmgr/aset.c src/backend/utils/mmgr/mcxt.c src/backend/utils/mmgr/portalmem.c src/backend/utils/sort/Makefile src/backend/utils/sort/logtape.c src/backend/utils/sort/tuplesort.c src/backend/utils/sort/tuplestore.c src/backend/utils/time/Makefile src/backend/utils/time/tqual.c src/bin/Makefile src/bin/initdb/Makefile src/bin/initdb/initdb.sh src/bin/initlocation/Makefile src/bin/initlocation/initlocation.sh src/bin/ipcclean/Makefile src/bin/ipcclean/ipcclean.sh src/bin/pg_config/Makefile src/bin/pg_config/pg_config.sh src/bin/pg_ctl/Makefile src/bin/pg_ctl/pg_ctl.sh src/bin/pg_dump/Makefile src/bin/pg_dump/README src/bin/pg_dump/common.c src/bin/pg_dump/cs.po src/bin/pg_dump/de.po src/bin/pg_dump/nls.mk src/bin/pg_dump/pg_backup.h src/bin/pg_dump/pg_backup_archiver.c src/bin/pg_dump/pg_backup_archiver.h src/bin/pg_dump/pg_backup_custom.c src/bin/pg_dump/pg_backup_db.c src/bin/pg_dump/pg_backup_db.h src/bin/pg_dump/pg_backup_files.c src/bin/pg_dump/pg_backup_null.c src/bin/pg_dump/pg_backup_tar.c src/bin/pg_dump/pg_backup_tar.h src/bin/pg_dump/pg_dump.c src/bin/pg_dump/pg_dump.h src/bin/pg_dump/pg_dumpall.sh src/bin/pg_dump/pg_restore.c src/bin/pg_dump/ru.po src/bin/pg_dump/sv.po src/bin/pg_dump/zh_CN.po src/bin/pg_dump/zh_TW.po src/bin/pg_encoding/Makefile src/bin/pg_encoding/pg_encoding.c src/bin/pg_id/Makefile src/bin/pg_id/pg_id.c src/bin/pgaccess/Makefile src/bin/pgaccess/README src/bin/pgaccess/copyright.html src/bin/pgaccess/demo/formdemo.sql src/bin/pgaccess/doc/html/a_right.gif src/bin/pgaccess/doc/html/addindex.gif src/bin/pgaccess/doc/html/api.html src/bin/pgaccess/doc/html/ball.gif src/bin/pgaccess/doc/html/contents.html src/bin/pgaccess/doc/html/copyright.html src/bin/pgaccess/doc/html/documentation.html src/bin/pgaccess/doc/html/download.html src/bin/pgaccess/doc/html/faq.html src/bin/pgaccess/doc/html/features.html src/bin/pgaccess/doc/html/formdemo.sql src/bin/pgaccess/doc/html/forms.gif src/bin/pgaccess/doc/html/forms.html src/bin/pgaccess/doc/html/function.gif src/bin/pgaccess/doc/html/help.gif src/bin/pgaccess/doc/html/index.html src/bin/pgaccess/doc/html/irix.html src/bin/pgaccess/doc/html/linux1.gif src/bin/pgaccess/doc/html/maillist.html src/bin/pgaccess/doc/html/main.html src/bin/pgaccess/doc/html/mainwindow.gif src/bin/pgaccess/doc/html/newtable.gif src/bin/pgaccess/doc/html/newuser.gif src/bin/pgaccess/doc/html/old_index.html src/bin/pgaccess/doc/html/permissions.gif src/bin/pgaccess/doc/html/pg93patch.html src/bin/pgaccess/doc/html/pga-rad.html src/bin/pgaccess/doc/html/qbtclet.html src/bin/pgaccess/doc/html/qbtclet.tcl src/bin/pgaccess/doc/html/screenshots.html src/bin/pgaccess/doc/html/specialchars.html src/bin/pgaccess/doc/html/todo.html src/bin/pgaccess/doc/html/tutorial/addref.jpg src/bin/pgaccess/doc/html/tutorial/altern_q.jpg src/bin/pgaccess/doc/html/tutorial/altern_v.jpg src/bin/pgaccess/doc/html/tutorial/copyright.html src/bin/pgaccess/doc/html/tutorial/index.html src/bin/pgaccess/doc/html/tutorial/intro.html src/bin/pgaccess/doc/html/tutorial/irix.html src/bin/pgaccess/doc/html/tutorial/newref.txt src/bin/pgaccess/doc/html/tutorial/newtable.jpg src/bin/pgaccess/doc/html/tutorial/newtable.tga src/bin/pgaccess/doc/html/tutorial/problems.html src/bin/pgaccess/doc/html/tutorial/screen1.jpg src/bin/pgaccess/doc/html/tutorial/sel_tbl.jpg src/bin/pgaccess/doc/html/tutorial/start.html src/bin/pgaccess/doc/html/tutorial/tut.html src/bin/pgaccess/doc/html/tutorial/tut_edit.html src/bin/pgaccess/doc/html/tutorial/tut_new.html src/bin/pgaccess/doc/html/tutorial/tut_sel1.html src/bin/pgaccess/doc/html/tutorial/tut_user.html src/bin/pgaccess/doc/html/vdesigner.gif src/bin/pgaccess/doc/html/whatsnew.html src/bin/pgaccess/doc/html/win32.html src/bin/pgaccess/images/icon_button.gif src/bin/pgaccess/images/icon_checkbutton.gif src/bin/pgaccess/images/icon_entry.gif src/bin/pgaccess/images/icon_frame.gif src/bin/pgaccess/images/icon_label.gif src/bin/pgaccess/images/icon_listbox.gif src/bin/pgaccess/images/icon_query.gif src/bin/pgaccess/images/icon_radiobutton.gif src/bin/pgaccess/images/icon_text.gif src/bin/pgaccess/lib/database.tcl src/bin/pgaccess/lib/forms.tcl src/bin/pgaccess/lib/functions.tcl src/bin/pgaccess/lib/help/abort.hlp src/bin/pgaccess/lib/help/add_records.hlp src/bin/pgaccess/lib/help/alter_table.hlp src/bin/pgaccess/lib/help/alter_user.hlp src/bin/pgaccess/lib/help/author.hlp src/bin/pgaccess/lib/help/begin.hlp src/bin/pgaccess/lib/help/close.hlp src/bin/pgaccess/lib/help/cluster.hlp src/bin/pgaccess/lib/help/commit.hlp src/bin/pgaccess/lib/help/copy.hlp src/bin/pgaccess/lib/help/copyrights.hlp src/bin/pgaccess/lib/help/create_aggregate.hlp src/bin/pgaccess/lib/help/create_database.hlp src/bin/pgaccess/lib/help/create_function.hlp src/bin/pgaccess/lib/help/create_index.hlp src/bin/pgaccess/lib/help/create_language.hlp src/bin/pgaccess/lib/help/create_operator.hlp src/bin/pgaccess/lib/help/create_rule.hlp src/bin/pgaccess/lib/help/create_sequence.hlp src/bin/pgaccess/lib/help/create_table.hlp src/bin/pgaccess/lib/help/create_table_as.hlp src/bin/pgaccess/lib/help/create_trigger.hlp src/bin/pgaccess/lib/help/create_type.hlp src/bin/pgaccess/lib/help/create_user.hlp src/bin/pgaccess/lib/help/create_view.hlp src/bin/pgaccess/lib/help/data_types.hlp src/bin/pgaccess/lib/help/datefunc.hlp src/bin/pgaccess/lib/help/declare.hlp src/bin/pgaccess/lib/help/delete.hlp src/bin/pgaccess/lib/help/drop_aggregate.hlp src/bin/pgaccess/lib/help/drop_database.hlp src/bin/pgaccess/lib/help/drop_function.hlp src/bin/pgaccess/lib/help/drop_index.hlp src/bin/pgaccess/lib/help/drop_language.hlp src/bin/pgaccess/lib/help/drop_operator.hlp src/bin/pgaccess/lib/help/drop_rule.hlp src/bin/pgaccess/lib/help/drop_sequence.hlp src/bin/pgaccess/lib/help/drop_table.hlp src/bin/pgaccess/lib/help/drop_trigger.hlp src/bin/pgaccess/lib/help/drop_type.hlp src/bin/pgaccess/lib/help/drop_user.hlp src/bin/pgaccess/lib/help/drop_view.hlp src/bin/pgaccess/lib/help/explain.hlp src/bin/pgaccess/lib/help/fetch.hlp src/bin/pgaccess/lib/help/form_design.hlp src/bin/pgaccess/lib/help/forms.hlp src/bin/pgaccess/lib/help/functions.hlp src/bin/pgaccess/lib/help/geomfunc.hlp src/bin/pgaccess/lib/help/grant.hlp src/bin/pgaccess/lib/help/history.hlp src/bin/pgaccess/lib/help/index.hlp src/bin/pgaccess/lib/help/inheritance.hlp src/bin/pgaccess/lib/help/insert.hlp src/bin/pgaccess/lib/help/ipv4func.hlp src/bin/pgaccess/lib/help/isolation.hlp src/bin/pgaccess/lib/help/keywords.hlp src/bin/pgaccess/lib/help/listen.hlp src/bin/pgaccess/lib/help/load.hlp src/bin/pgaccess/lib/help/lock.hlp src/bin/pgaccess/lib/help/mathfunc.hlp src/bin/pgaccess/lib/help/move.hlp src/bin/pgaccess/lib/help/mvcc.hlp src/bin/pgaccess/lib/help/new_query.hlp src/bin/pgaccess/lib/help/new_table.hlp src/bin/pgaccess/lib/help/notify.hlp src/bin/pgaccess/lib/help/open_query.hlp src/bin/pgaccess/lib/help/open_table.hlp src/bin/pgaccess/lib/help/pgfunctions.hlp src/bin/pgaccess/lib/help/postgresql.hlp src/bin/pgaccess/lib/help/queries.hlp src/bin/pgaccess/lib/help/reports.hlp src/bin/pgaccess/lib/help/reset.hlp src/bin/pgaccess/lib/help/revoke.hlp src/bin/pgaccess/lib/help/rollback.hlp src/bin/pgaccess/lib/help/schema.hlp src/bin/pgaccess/lib/help/scripts.hlp src/bin/pgaccess/lib/help/select.hlp src/bin/pgaccess/lib/help/select_into.hlp src/bin/pgaccess/lib/help/sequences.hlp src/bin/pgaccess/lib/help/set.hlp src/bin/pgaccess/lib/help/show.hlp src/bin/pgaccess/lib/help/sql_guide.hlp src/bin/pgaccess/lib/help/sqlfunc.hlp src/bin/pgaccess/lib/help/stringfunc.hlp src/bin/pgaccess/lib/help/tables.hlp src/bin/pgaccess/lib/help/unlisten.hlp src/bin/pgaccess/lib/help/update.hlp src/bin/pgaccess/lib/help/users.hlp src/bin/pgaccess/lib/help/vacuum.hlp src/bin/pgaccess/lib/help/view_table_structure.hlp src/bin/pgaccess/lib/help/views.hlp src/bin/pgaccess/lib/help/visual_designer.hlp src/bin/pgaccess/lib/help/y2k.hlp src/bin/pgaccess/lib/help.tcl src/bin/pgaccess/lib/languages/chinese_big5 src/bin/pgaccess/lib/languages/chinese_gb src/bin/pgaccess/lib/languages/czech src/bin/pgaccess/lib/languages/deutsch src/bin/pgaccess/lib/languages/euskara src/bin/pgaccess/lib/languages/francais src/bin/pgaccess/lib/languages/italiano src/bin/pgaccess/lib/languages/japanese src/bin/pgaccess/lib/languages/magyar src/bin/pgaccess/lib/languages/nederlands src/bin/pgaccess/lib/languages/portugues src/bin/pgaccess/lib/languages/romana src/bin/pgaccess/lib/languages/russian.koi8r src/bin/pgaccess/lib/languages/russian_win src/bin/pgaccess/lib/languages/spanish src/bin/pgaccess/lib/mainlib.tcl src/bin/pgaccess/lib/preferences.tcl src/bin/pgaccess/lib/queries.tcl src/bin/pgaccess/lib/reports.tcl src/bin/pgaccess/lib/schema.tcl src/bin/pgaccess/lib/scripts.tcl src/bin/pgaccess/lib/sequences.tcl src/bin/pgaccess/lib/tables.tcl src/bin/pgaccess/lib/users.tcl src/bin/pgaccess/lib/views.tcl src/bin/pgaccess/lib/visualqb.tcl src/bin/pgaccess/main.tcl src/bin/pgaccess/pgaccess.sh src/bin/pgtclsh/Makefile src/bin/pgtclsh/README src/bin/pgtclsh/pgtclAppInit.c src/bin/pgtclsh/pgtclUtils.tcl src/bin/pgtclsh/pgtkAppInit.c src/bin/pgtclsh/updateStats.tcl src/bin/psql/.cvsignore src/bin/psql/Makefile src/bin/psql/command.c src/bin/psql/command.h src/bin/psql/common.c src/bin/psql/common.h src/bin/psql/copy.c src/bin/psql/copy.h src/bin/psql/create_help.pl src/bin/psql/cs.po src/bin/psql/de.po src/bin/psql/describe.c src/bin/psql/describe.h src/bin/psql/fr.po src/bin/psql/help.c src/bin/psql/help.h src/bin/psql/input.c src/bin/psql/input.h src/bin/psql/large_obj.c src/bin/psql/large_obj.h src/bin/psql/mainloop.c src/bin/psql/mainloop.h src/bin/psql/mbprint.c src/bin/psql/mbprint.h src/bin/psql/nls.mk src/bin/psql/print.c src/bin/psql/print.h src/bin/psql/prompt.c src/bin/psql/prompt.h src/bin/psql/ru.po src/bin/psql/settings.h src/bin/psql/startup.c src/bin/psql/stringutils.c src/bin/psql/stringutils.h src/bin/psql/sv.po src/bin/psql/tab-complete.c src/bin/psql/tab-complete.h src/bin/psql/variables.c src/bin/psql/variables.h src/bin/psql/win32.mak src/bin/psql/zh_CN.po src/bin/psql/zh_TW.po src/bin/scripts/Makefile src/bin/scripts/createdb src/bin/scripts/createlang.sh src/bin/scripts/createuser src/bin/scripts/dropdb src/bin/scripts/droplang src/bin/scripts/dropuser src/bin/scripts/vacuumdb src/corba/CosQuery.idl src/corba/CosQueryCollection.idl src/corba/pgsql.idl src/corba/pgsql_int.idl src/corba/server.cc src/data/charset.conf src/data/isocz-wincz.tab src/data/koi-alt.tab src/data/koi-iso.tab src/data/koi-koi.tab src/data/koi-mac.tab src/data/koi-win.tab src/include/Makefile src/include/access/attnum.h src/include/access/clog.h src/include/access/genam.h src/include/access/gist.h src/include/access/gistscan.h src/include/access/hash.h src/include/access/heapam.h src/include/access/hio.h src/include/access/htup.h src/include/access/ibit.h src/include/access/iqual.h src/include/access/istrat.h src/include/access/itup.h src/include/access/nbtree.h src/include/access/printtup.h src/include/access/relscan.h src/include/access/rmgr.h src/include/access/rtree.h src/include/access/rtscan.h src/include/access/sdir.h src/include/access/skey.h src/include/access/strat.h src/include/access/transam.h src/include/access/tupdesc.h src/include/access/tupmacs.h src/include/access/tuptoaster.h src/include/access/valid.h src/include/access/xact.h src/include/access/xlog.h src/include/access/xlogdefs.h src/include/access/xlogutils.h src/include/bootstrap/bootstrap.h src/include/c.h src/include/catalog/catalog.h src/include/catalog/catname.h src/include/catalog/catversion.h src/include/catalog/duplicate_oids src/include/catalog/heap.h src/include/catalog/index.h src/include/catalog/indexing.h src/include/catalog/namespace.h src/include/catalog/pg_aggregate.h src/include/catalog/pg_am.h src/include/catalog/pg_amop.h src/include/catalog/pg_amproc.h src/include/catalog/pg_attrdef.h src/include/catalog/pg_attribute.h src/include/catalog/pg_class.h src/include/catalog/pg_control.h src/include/catalog/pg_database.h src/include/catalog/pg_description.h src/include/catalog/pg_group.h src/include/catalog/pg_index.h src/include/catalog/pg_inherits.h src/include/catalog/pg_language.h src/include/catalog/pg_largeobject.h src/include/catalog/pg_listener.h src/include/catalog/pg_namespace.h src/include/catalog/pg_opclass.h src/include/catalog/pg_operator.h src/include/catalog/pg_proc.h src/include/catalog/pg_relcheck.h src/include/catalog/pg_rewrite.h src/include/catalog/pg_shadow.h src/include/catalog/pg_statistic.h src/include/catalog/pg_trigger.h src/include/catalog/pg_type.h src/include/catalog/pg_version.h src/include/catalog/unused_oids src/include/commands/async.h src/include/commands/cluster.h src/include/commands/comment.h src/include/commands/copy.h src/include/commands/dbcommands.h src/include/commands/defrem.h src/include/commands/explain.h src/include/commands/lockcmds.h src/include/commands/portalcmds.h src/include/commands/proclang.h src/include/commands/schemacmds.h src/include/commands/sequence.h src/include/commands/tablecmds.h src/include/commands/trigger.h src/include/commands/user.h src/include/commands/vacuum.h src/include/commands/variable.h src/include/commands/version.h src/include/commands/view.h src/include/executor/execdebug.h src/include/executor/execdefs.h src/include/executor/execdesc.h src/include/executor/executor.h src/include/executor/functions.h src/include/executor/hashjoin.h src/include/executor/instrument.h src/include/executor/nodeAgg.h src/include/executor/nodeAppend.h src/include/executor/nodeFunctionscan.h src/include/executor/nodeGroup.h src/include/executor/nodeHash.h src/include/executor/nodeHashjoin.h src/include/executor/nodeIndexscan.h src/include/executor/nodeLimit.h src/include/executor/nodeMaterial.h src/include/executor/nodeMergejoin.h src/include/executor/nodeNestloop.h src/include/executor/nodeResult.h src/include/executor/nodeSeqscan.h src/include/executor/nodeSetOp.h src/include/executor/nodeSort.h src/include/executor/nodeSubplan.h src/include/executor/nodeSubqueryscan.h src/include/executor/nodeTidscan.h src/include/executor/nodeUnique.h src/include/executor/spi.h src/include/executor/spi_priv.h src/include/executor/tuptable.h src/include/fmgr.h src/include/lib/dllist.h src/include/lib/lispsort.h src/include/lib/stringinfo.h src/include/libpq/auth.h src/include/libpq/be-fsstubs.h src/include/libpq/crypt.h src/include/libpq/hba.h src/include/libpq/libpq-be.h src/include/libpq/libpq-fs.h src/include/libpq/libpq.h src/include/libpq/password.h src/include/libpq/pqcomm.h src/include/libpq/pqformat.h src/include/libpq/pqsignal.h src/include/mb/pg_wchar.h src/include/miscadmin.h src/include/nodes/execnodes.h src/include/nodes/makefuncs.h src/include/nodes/memnodes.h src/include/nodes/nodeFuncs.h src/include/nodes/nodes.h src/include/nodes/params.h src/include/nodes/parsenodes.h src/include/nodes/pg_list.h src/include/nodes/plannodes.h src/include/nodes/primnodes.h src/include/nodes/print.h src/include/nodes/readfuncs.h src/include/nodes/relation.h src/include/optimizer/_deadcode/xfunc.h src/include/optimizer/clauses.h src/include/optimizer/cost.h src/include/optimizer/geqo.h src/include/optimizer/geqo_copy.h src/include/optimizer/geqo_gene.h src/include/optimizer/geqo_misc.h src/include/optimizer/geqo_mutation.h src/include/optimizer/geqo_pool.h src/include/optimizer/geqo_random.h src/include/optimizer/geqo_recombination.h src/include/optimizer/geqo_selection.h src/include/optimizer/joininfo.h src/include/optimizer/pathnode.h src/include/optimizer/paths.h src/include/optimizer/plancat.h src/include/optimizer/planmain.h src/include/optimizer/planner.h src/include/optimizer/prep.h src/include/optimizer/restrictinfo.h src/include/optimizer/subselect.h src/include/optimizer/tlist.h src/include/optimizer/var.h src/include/parser/analyze.h src/include/parser/gramparse.h src/include/parser/keywords.h src/include/parser/parse_agg.h src/include/parser/parse_clause.h src/include/parser/parse_coerce.h src/include/parser/parse_expr.h src/include/parser/parse_func.h src/include/parser/parse_node.h src/include/parser/parse_oper.h src/include/parser/parse_relation.h src/include/parser/parse_target.h src/include/parser/parse_type.h src/include/parser/parser.h src/include/parser/parsetree.h src/include/parser/scansup.h src/include/pg_config.h.in src/include/pg_config.h.win32 src/include/pgstat.h src/include/port/aix.h src/include/port/beos.h src/include/port/bsdi.h src/include/port/darwin.h src/include/port/dgux.h src/include/port/freebsd.h src/include/port/hpux.h src/include/port/irix5.h src/include/port/linux.h src/include/port/netbsd.h src/include/port/nextstep.h src/include/port/openbsd.h src/include/port/osf.h src/include/port/qnx4.h src/include/port/sco.h src/include/port/solaris.h src/include/port/sunos4.h src/include/port/svr4.h src/include/port/ultrix4.h src/include/port/univel.h src/include/port/unixware.h src/include/port/win.h src/include/port/win32.h src/include/postgres.h src/include/postgres_ext.h src/include/postgres_fe.h src/include/regex/cclass.h src/include/regex/cname.h src/include/regex/regex.h src/include/regex/regex2.h src/include/regex/utils.h src/include/rewrite/prs2lock.h src/include/rewrite/rewriteDefine.h src/include/rewrite/rewriteHandler.h src/include/rewrite/rewriteManip.h src/include/rewrite/rewriteRemove.h src/include/rewrite/rewriteSupport.h src/include/rusagestub.h src/include/storage/backendid.h src/include/storage/block.h src/include/storage/buf.h src/include/storage/buf_internals.h src/include/storage/buffile.h src/include/storage/bufmgr.h src/include/storage/bufpage.h src/include/storage/fd.h src/include/storage/freespace.h src/include/storage/ipc.h src/include/storage/item.h src/include/storage/itemid.h src/include/storage/itempos.h src/include/storage/itemptr.h src/include/storage/large_object.h src/include/storage/lmgr.h src/include/storage/lock.h src/include/storage/lwlock.h src/include/storage/off.h src/include/storage/page.h src/include/storage/pg_sema.h src/include/storage/pg_shmem.h src/include/storage/pmsignal.h src/include/storage/pos.h src/include/storage/proc.h src/include/storage/relfilenode.h src/include/storage/s_lock.h src/include/storage/shmem.h src/include/storage/sinval.h src/include/storage/sinvaladt.h src/include/storage/smgr.h src/include/storage/spin.h src/include/strdup.h src/include/tcop/dest.h src/include/tcop/fastpath.h src/include/tcop/pquery.h src/include/tcop/tcopdebug.h src/include/tcop/tcopprot.h src/include/tcop/utility.h src/include/utils/acl.h src/include/utils/array.h src/include/utils/ascii.h src/include/utils/bit.h src/include/utils/builtins.h src/include/utils/cash.h src/include/utils/catcache.h src/include/utils/date.h src/include/utils/datetime.h src/include/utils/datum.h src/include/utils/dynahash.h src/include/utils/dynamic_loader.h src/include/utils/elog.h src/include/utils/exc.h src/include/utils/excid.h src/include/utils/fcache.h src/include/utils/fmgrtab.h src/include/utils/formatting.h src/include/utils/geo_decls.h src/include/utils/guc.h src/include/utils/hsearch.h src/include/utils/inet.h src/include/utils/int8.h src/include/utils/inval.h src/include/utils/logtape.h src/include/utils/lsyscache.h src/include/utils/memutils.h src/include/utils/nabstime.h src/include/utils/numeric.h src/include/utils/palloc.h src/include/utils/pg_crc.h src/include/utils/pg_locale.h src/include/utils/pg_lzcompress.h src/include/utils/portal.h src/include/utils/ps_status.h src/include/utils/rel.h src/include/utils/relcache.h src/include/utils/selfuncs.h src/include/utils/sets.h src/include/utils/syscache.h src/include/utils/timestamp.h src/include/utils/tqual.h src/include/utils/tuplesort.h src/include/utils/tuplestore.h src/include/utils/varbit.h src/interfaces/Makefile src/interfaces/cli/example1.c src/interfaces/cli/example2.c src/interfaces/cli/sqlcli.h src/interfaces/jdbc/CHANGELOG src/interfaces/jdbc/Implementation src/interfaces/jdbc/Makefile src/interfaces/jdbc/README src/interfaces/jdbc/build.xml src/interfaces/jdbc/example/ImageViewer.java src/interfaces/jdbc/example/Unicode.java src/interfaces/jdbc/example/basic.java src/interfaces/jdbc/example/blobtest.java src/interfaces/jdbc/example/corba/StockClient.java src/interfaces/jdbc/example/corba/StockDB.java src/interfaces/jdbc/example/corba/StockDispenserImpl.java src/interfaces/jdbc/example/corba/StockItemImpl.java src/interfaces/jdbc/example/corba/StockServer.java src/interfaces/jdbc/example/corba/readme src/interfaces/jdbc/example/corba/stock.idl src/interfaces/jdbc/example/corba/stock.sql src/interfaces/jdbc/example/datestyle.java src/interfaces/jdbc/example/metadata.java src/interfaces/jdbc/example/psql.java src/interfaces/jdbc/example/threadsafe.java src/interfaces/jdbc/jdbc.jpx src/interfaces/jdbc/org/postgresql/Connection.java src/interfaces/jdbc/org/postgresql/Driver.java.in src/interfaces/jdbc/org/postgresql/Field.java src/interfaces/jdbc/org/postgresql/PG_Stream.java src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java src/interfaces/jdbc/org/postgresql/ResultSet.java src/interfaces/jdbc/org/postgresql/Statement.java src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java src/interfaces/jdbc/org/postgresql/core/Encoding.java src/interfaces/jdbc/org/postgresql/core/MemoryPool.java src/interfaces/jdbc/org/postgresql/core/ObjectPool.java src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java src/interfaces/jdbc/org/postgresql/core/SimpleObjectPool.java src/interfaces/jdbc/org/postgresql/core/StartupPacket.java src/interfaces/jdbc/org/postgresql/errors.properties src/interfaces/jdbc/org/postgresql/errors_de.properties src/interfaces/jdbc/org/postgresql/errors_fr.properties src/interfaces/jdbc/org/postgresql/errors_it.properties src/interfaces/jdbc/org/postgresql/errors_nl.properties src/interfaces/jdbc/org/postgresql/errors_zh_TW.properties src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java src/interfaces/jdbc/org/postgresql/geometric/PGbox.java src/interfaces/jdbc/org/postgresql/geometric/PGcircle.java src/interfaces/jdbc/org/postgresql/geometric/PGline.java src/interfaces/jdbc/org/postgresql/geometric/PGlseg.java src/interfaces/jdbc/org/postgresql/geometric/PGpath.java src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java src/interfaces/jdbc/org/postgresql/jdbc1/CallableStatement.java src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java src/interfaces/jdbc/org/postgresql/jdbc1/Statement.java src/interfaces/jdbc/org/postgresql/jdbc2/Array.java src/interfaces/jdbc/org/postgresql/jdbc2/CallableStatement.java src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java src/interfaces/jdbc/org/postgresql/jdbc2/PBatchUpdateException.java src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java src/interfaces/jdbc/org/postgresql/jdbc2/Statement.java src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java src/interfaces/jdbc/org/postgresql/largeobject/BlobOutputStream.java src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java src/interfaces/jdbc/org/postgresql/largeobject/PGblob.java src/interfaces/jdbc/org/postgresql/largeobject/PGclob.java src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java src/interfaces/jdbc/org/postgresql/test/README src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/DateTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/EncodingTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/TimeTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/TimestampTest.java src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java src/interfaces/jdbc/org/postgresql/util/MD5Digest.java src/interfaces/jdbc/org/postgresql/util/MessageTranslator.java src/interfaces/jdbc/org/postgresql/util/PGbytea.java src/interfaces/jdbc/org/postgresql/util/PGmoney.java src/interfaces/jdbc/org/postgresql/util/PGobject.java src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java src/interfaces/jdbc/org/postgresql/util/PSQLException.java src/interfaces/jdbc/org/postgresql/util/Serialize.java src/interfaces/jdbc/org/postgresql/util/UnixCrypt.java src/interfaces/jdbc/org/postgresql/xa/ClientConnection.java src/interfaces/jdbc/org/postgresql/xa/TwoPhaseConnection.java src/interfaces/jdbc/org/postgresql/xa/TxConnection.java src/interfaces/jdbc/org/postgresql/xa/XAConnectionImpl.java src/interfaces/jdbc/org/postgresql/xa/XADataSourceImpl.java src/interfaces/jdbc/utils/CheckVersion.java src/interfaces/jdbc/utils/buildDriver src/interfaces/jdbc/utils/changelog.pl src/interfaces/libpgeasy/Makefile src/interfaces/libpgeasy/README src/interfaces/libpgeasy/examples/Makefile src/interfaces/libpgeasy/examples/pginsert.c src/interfaces/libpgeasy/examples/pgmultiresult.c src/interfaces/libpgeasy/examples/pgnulltest.c src/interfaces/libpgeasy/examples/pgwordcount.c src/interfaces/libpgeasy/halt.c src/interfaces/libpgeasy/halt.h src/interfaces/libpgeasy/libpgeasy.c src/interfaces/libpgeasy/libpgeasy.h src/interfaces/libpgtcl/Makefile src/interfaces/libpgtcl/README src/interfaces/libpgtcl/libpgtcl.def src/interfaces/libpgtcl/libpgtcl.h src/interfaces/libpgtcl/pgtcl.c src/interfaces/libpgtcl/pgtclCmds.c src/interfaces/libpgtcl/pgtclCmds.h src/interfaces/libpgtcl/pgtclId.c src/interfaces/libpgtcl/pgtclId.h src/interfaces/libpgtcl/win32.mak src/interfaces/libpq/Makefile src/interfaces/libpq/README src/interfaces/libpq/cs.po src/interfaces/libpq/de.po src/interfaces/libpq/fe-auth.c src/interfaces/libpq/fe-auth.h src/interfaces/libpq/fe-connect.c src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-lobj.c src/interfaces/libpq/fe-misc.c src/interfaces/libpq/fe-print.c src/interfaces/libpq/fe-secure.c src/interfaces/libpq/fr.po src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-int.h src/interfaces/libpq/libpq.rc src/interfaces/libpq/libpqdll.c src/interfaces/libpq/libpqdll.def src/interfaces/libpq/nls.mk src/interfaces/libpq/pqexpbuffer.c src/interfaces/libpq/pqexpbuffer.h src/interfaces/libpq/pqsignal.c src/interfaces/libpq/pqsignal.h src/interfaces/libpq/ru.po src/interfaces/libpq/sv.po src/interfaces/libpq/win32.c src/interfaces/libpq/win32.h src/interfaces/libpq/win32.mak src/interfaces/libpq/zh_CN.po src/interfaces/libpq/zh_TW.po src/interfaces/libpq++/CHANGES src/interfaces/libpq++/Makefile src/interfaces/libpq++/README src/interfaces/libpq++/TODO src/interfaces/libpq++/examples/Makefile src/interfaces/libpq++/examples/testlibpq0.cc src/interfaces/libpq++/examples/testlibpq1.cc src/interfaces/libpq++/examples/testlibpq2.cc src/interfaces/libpq++/examples/testlibpq2.sql src/interfaces/libpq++/examples/testlibpq3.cc src/interfaces/libpq++/examples/testlibpq3.sql src/interfaces/libpq++/examples/testlibpq4.cc src/interfaces/libpq++/examples/testlibpq4.sql src/interfaces/libpq++/examples/testlibpq5.cc src/interfaces/libpq++/examples/testlibpq5.sql src/interfaces/libpq++/examples/testlibpq6.cc src/interfaces/libpq++/examples/testlo.cc src/interfaces/libpq++/libpq++.h src/interfaces/libpq++/libpq++dll.rc src/interfaces/libpq++/pgconnection.cc src/interfaces/libpq++/pgconnection.h src/interfaces/libpq++/pgcursordb.cc src/interfaces/libpq++/pgcursordb.h src/interfaces/libpq++/pgdatabase.cc src/interfaces/libpq++/pgdatabase.h src/interfaces/libpq++/pglobject.cc src/interfaces/libpq++/pglobject.h src/interfaces/libpq++/pgtransdb.cc src/interfaces/libpq++/pgtransdb.h src/interfaces/libpq++/win32.mak src/interfaces/odbc/GNUmakefile src/interfaces/odbc/bind.c src/interfaces/odbc/bind.h src/interfaces/odbc/columninfo.c src/interfaces/odbc/columninfo.h src/interfaces/odbc/connection.c src/interfaces/odbc/connection.h src/interfaces/odbc/convert.c src/interfaces/odbc/convert.h src/interfaces/odbc/descriptor.h src/interfaces/odbc/dlg_specific.c src/interfaces/odbc/dlg_specific.h src/interfaces/odbc/dlg_wingui.c src/interfaces/odbc/drvconn.c src/interfaces/odbc/environ.c src/interfaces/odbc/environ.h src/interfaces/odbc/execute.c src/interfaces/odbc/gpps.c src/interfaces/odbc/gpps.h src/interfaces/odbc/info.c src/interfaces/odbc/info30.c src/interfaces/odbc/iodbc.h src/interfaces/odbc/isql.h src/interfaces/odbc/isqlext.h src/interfaces/odbc/license.txt src/interfaces/odbc/lobj.c src/interfaces/odbc/lobj.h src/interfaces/odbc/md5.c src/interfaces/odbc/md5.h src/interfaces/odbc/misc.c src/interfaces/odbc/misc.h src/interfaces/odbc/multibyte.c src/interfaces/odbc/multibyte.h src/interfaces/odbc/notice.txt src/interfaces/odbc/odbc.sql src/interfaces/odbc/odbcapi.c src/interfaces/odbc/odbcapi25w.c src/interfaces/odbc/odbcapi30.c src/interfaces/odbc/odbcapi30w.c src/interfaces/odbc/odbcapiw.c src/interfaces/odbc/odbcinst.ini src/interfaces/odbc/options.c src/interfaces/odbc/parse.c src/interfaces/odbc/pgapi30.c src/interfaces/odbc/pgapifunc.h src/interfaces/odbc/pgtypes.c src/interfaces/odbc/pgtypes.h src/interfaces/odbc/psqlodbc.c src/interfaces/odbc/psqlodbc.h src/interfaces/odbc/psqlodbc.rc src/interfaces/odbc/psqlodbc.reg src/interfaces/odbc/psqlodbc30.reg src/interfaces/odbc/psqlodbc30w.reg src/interfaces/odbc/psqlodbc_api30.def src/interfaces/odbc/psqlodbc_api30w.def src/interfaces/odbc/psqlodbc_apiw.def src/interfaces/odbc/psqlodbc_win32.def src/interfaces/odbc/qresult.c src/interfaces/odbc/qresult.h src/interfaces/odbc/readme.txt src/interfaces/odbc/resource.h src/interfaces/odbc/results.c src/interfaces/odbc/setup.c src/interfaces/odbc/setup.rul src/interfaces/odbc/socket.c src/interfaces/odbc/socket.h src/interfaces/odbc/statement.c src/interfaces/odbc/statement.h src/interfaces/odbc/tuple.c src/interfaces/odbc/tuple.h src/interfaces/odbc/tuplelist.c src/interfaces/odbc/tuplelist.h src/interfaces/odbc/version.h src/interfaces/odbc/win32.mak src/interfaces/odbc/win32_30.mak src/interfaces/odbc/win32_30w.mak src/interfaces/odbc/win32w.mak src/interfaces/odbc/win_md5.c src/interfaces/odbc/win_setup.h src/interfaces/odbc/win_unicode.c src/interfaces/perl5/Changes src/interfaces/perl5/GNUmakefile src/interfaces/perl5/MANIFEST src/interfaces/perl5/Makefile.PL src/interfaces/perl5/Pg.pm src/interfaces/perl5/Pg.xs src/interfaces/perl5/README src/interfaces/perl5/examples/ApachePg.pl src/interfaces/perl5/examples/example.newstyle src/interfaces/perl5/examples/example.oldstyle src/interfaces/perl5/ppport.h src/interfaces/perl5/test.pl src/interfaces/perl5/typemap src/interfaces/python/Announce src/interfaces/python/ChangeLog src/interfaces/python/GNUmakefile src/interfaces/python/PyGreSQL.spec src/interfaces/python/README src/interfaces/python/README.linux src/interfaces/python/Setup.in.raw src/interfaces/python/pg.py src/interfaces/python/pgdb.py src/interfaces/python/pgmodule.c src/interfaces/python/setup.py src/interfaces/python/tutorial/advanced.py src/interfaces/python/tutorial/basics.py src/interfaces/python/tutorial/func.py src/interfaces/python/tutorial/syscat.py src/interfaces/ssl/client.conf src/interfaces/ssl/mkcert.sh src/interfaces/ssl/pgkeygen.sh src/interfaces/ssl/root.conf src/interfaces/ssl/server.conf src/makefiles/Makefile.aix src/makefiles/Makefile.beos src/makefiles/Makefile.bsdi src/makefiles/Makefile.darwin src/makefiles/Makefile.dgux src/makefiles/Makefile.freebsd src/makefiles/Makefile.hpux src/makefiles/Makefile.irix5 src/makefiles/Makefile.linux src/makefiles/Makefile.netbsd src/makefiles/Makefile.openbsd src/makefiles/Makefile.osf src/makefiles/Makefile.qnx4 src/makefiles/Makefile.sco src/makefiles/Makefile.solaris src/makefiles/Makefile.sunos4 src/makefiles/Makefile.svr4 src/makefiles/Makefile.ultrix4 src/makefiles/Makefile.univel src/makefiles/Makefile.unixware src/makefiles/Makefile.win src/nls-global.mk src/pl/Makefile src/pl/plperl/GNUmakefile src/pl/plperl/README src/pl/plperl/SPI.xs src/pl/plperl/eloglvl.c src/pl/plperl/eloglvl.h src/pl/plperl/plperl.c src/pl/plperl/ppport.h src/pl/plpgsql/Makefile src/pl/plpgsql/src/.cvsignore src/pl/plpgsql/src/INSTALL src/pl/plpgsql/src/Makefile src/pl/plpgsql/src/gram.y src/pl/plpgsql/src/pl_comp.c src/pl/plpgsql/src/pl_exec.c src/pl/plpgsql/src/pl_funcs.c src/pl/plpgsql/src/pl_handler.c src/pl/plpgsql/src/plpgsql.h src/pl/plpgsql/src/scan.l src/pl/plpgsql/test/README src/pl/plpgsql/test/expected/tables.out src/pl/plpgsql/test/expected/test.out src/pl/plpgsql/test/expected/triggers.out src/pl/plpgsql/test/expected/views.out src/pl/plpgsql/test/runtest src/pl/plpgsql/test/tables.sql src/pl/plpgsql/test/test.sql src/pl/plpgsql/test/triggers.sql src/pl/plpgsql/test/views.sql src/pl/plpython/Makefile src/pl/plpython/README src/pl/plpython/TODO src/pl/plpython/error.expected src/pl/plpython/feature.expected src/pl/plpython/plpython.c src/pl/plpython/plpython.h src/pl/plpython/plpython_depopulate.sql src/pl/plpython/plpython_deschema.sql src/pl/plpython/plpython_drop.sql src/pl/plpython/plpython_error.sql src/pl/plpython/plpython_function.sql src/pl/plpython/plpython_populate.sql src/pl/plpython/plpython_schema.sql src/pl/plpython/plpython_setof.sql src/pl/plpython/plpython_test.sql src/pl/plpython/test.sh src/pl/tcl/Makefile src/pl/tcl/license.terms src/pl/tcl/modules/Makefile src/pl/tcl/modules/README src/pl/tcl/modules/pltcl_delmod.in src/pl/tcl/modules/pltcl_listmod.in src/pl/tcl/modules/pltcl_loadmod.in src/pl/tcl/modules/unknown.pltcl src/pl/tcl/pltcl.c src/pl/tcl/test/README src/pl/tcl/test/runtest src/pl/tcl/test/test.expected src/pl/tcl/test/test_queries.sql src/pl/tcl/test/test_setup.sql src/template/aix src/template/beos src/template/bsdi src/template/darwin src/template/dgux src/template/freebsd src/template/hpux src/template/irix5 src/template/linux src/template/netbsd src/template/nextstep src/template/openbsd src/template/osf src/template/qnx4 src/template/sco src/template/solaris src/template/sunos4 src/template/svr4 src/template/ultrix4 src/template/univel src/template/unixware src/template/win src/test/Makefile src/test/bench/Makefile src/test/bench/WISC-README src/test/bench/create.sh src/test/bench/create.source src/test/bench/perquery src/test/bench/query01 src/test/bench/query02 src/test/bench/query03 src/test/bench/query04 src/test/bench/query05 src/test/bench/query06 src/test/bench/query07 src/test/bench/query08 src/test/bench/query09 src/test/bench/query10 src/test/bench/query11 src/test/bench/query12 src/test/bench/query13 src/test/bench/query14 src/test/bench/query15 src/test/bench/query16 src/test/bench/query17 src/test/bench/query18 src/test/bench/query19 src/test/bench/query20 src/test/bench/query21 src/test/bench/query22 src/test/bench/query23 src/test/bench/query24 src/test/bench/query25 src/test/bench/query26 src/test/bench/query27 src/test/bench/query28 src/test/bench/query29 src/test/bench/query30 src/test/bench/query31 src/test/bench/query32 src/test/bench/runwisc.sh src/test/bench/wholebench.sh src/test/examples/Makefile src/test/examples/testlibpq.c src/test/examples/testlibpq2.c src/test/examples/testlibpq2.sql src/test/examples/testlibpq3.c src/test/examples/testlibpq3.sql src/test/examples/testlibpq4.c src/test/examples/testlo.c src/test/locale/Makefile src/test/locale/README src/test/locale/de_DE.ISO8859-1/Makefile src/test/locale/de_DE.ISO8859-1/README src/test/locale/de_DE.ISO8859-1/expected/de-ctype.out src/test/locale/de_DE.ISO8859-1/expected/test-de-char.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-select.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-sort.out src/test/locale/de_DE.ISO8859-1/expected/test-de-text.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-upper-char.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-upper-text.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-upper-varchar.sql.out src/test/locale/de_DE.ISO8859-1/expected/test-de-varchar.sql.out src/test/locale/de_DE.ISO8859-1/runall src/test/locale/de_DE.ISO8859-1/test-de-select.sql.in src/test/locale/de_DE.ISO8859-1/test-de-sort.in src/test/locale/de_DE.ISO8859-1/test-de-upper.sql.in src/test/locale/de_DE.ISO8859-1/test-de.sql.in src/test/locale/gr_GR.ISO8859-7/Makefile src/test/locale/gr_GR.ISO8859-7/README src/test/locale/gr_GR.ISO8859-7/expected/gr-ctype.out src/test/locale/gr_GR.ISO8859-7/expected/test-gr-char.sql.out src/test/locale/gr_GR.ISO8859-7/expected/test-gr-select.sql.out src/test/locale/gr_GR.ISO8859-7/expected/test-gr-sort.out src/test/locale/gr_GR.ISO8859-7/expected/test-gr-text.sql.out src/test/locale/gr_GR.ISO8859-7/expected/test-gr-varchar.sql.out src/test/locale/gr_GR.ISO8859-7/runall src/test/locale/gr_GR.ISO8859-7/test-gr-select.sql.in src/test/locale/gr_GR.ISO8859-7/test-gr-sort.in src/test/locale/gr_GR.ISO8859-7/test-gr.sql.in src/test/locale/koi8-r/Makefile src/test/locale/koi8-r/expected/koi8-ctype.out src/test/locale/koi8-r/expected/test-koi8-char.sql.out src/test/locale/koi8-r/expected/test-koi8-select.sql.out src/test/locale/koi8-r/expected/test-koi8-sort.out src/test/locale/koi8-r/expected/test-koi8-text.sql.out src/test/locale/koi8-r/expected/test-koi8-varchar.sql.out src/test/locale/koi8-r/runall src/test/locale/koi8-r/test-koi8-select.sql.in src/test/locale/koi8-r/test-koi8-sort.in src/test/locale/koi8-r/test-koi8.sql.in src/test/locale/koi8-to-win1251/Makefile src/test/locale/koi8-to-win1251/README src/test/locale/koi8-to-win1251/expected/test-koi8-char.sql.out src/test/locale/koi8-to-win1251/expected/test-koi8-select.sql.out src/test/locale/koi8-to-win1251/expected/test-koi8-sort.out src/test/locale/koi8-to-win1251/expected/test-koi8-text.sql.out src/test/locale/koi8-to-win1251/expected/test-koi8-varchar.sql.out src/test/locale/koi8-to-win1251/runall src/test/locale/koi8-to-win1251/test-koi8-select.sql.in src/test/locale/koi8-to-win1251/test-koi8-sort.in src/test/locale/koi8-to-win1251/test-koi8.sql.in src/test/locale/sort-test.pl src/test/locale/sort-test.py src/test/locale/test-ctype.c src/test/locale/test-pgsql-locale.c src/test/mb/README src/test/mb/expected/big5.out src/test/mb/expected/euc_cn.out src/test/mb/expected/euc_jp.out src/test/mb/expected/euc_kr.out src/test/mb/expected/euc_tw.out src/test/mb/expected/mule_internal.out src/test/mb/expected/sjis.out src/test/mb/expected/unicode.out src/test/mb/mbregress.sh src/test/mb/sql/big5.sql src/test/mb/sql/euc_cn.sql src/test/mb/sql/euc_jp.sql src/test/mb/sql/euc_kr.sql src/test/mb/sql/euc_tw.sql src/test/mb/sql/mule_internal.sql src/test/mb/sql/sjis.sql src/test/mb/sql/unicode.sql src/test/performance/results/PgSQL.970926 src/test/performance/runtests.pl src/test/performance/sqls/connection src/test/performance/sqls/crtsimple src/test/performance/sqls/crtsimpleidx src/test/performance/sqls/drpsimple src/test/performance/sqls/inssimple src/test/performance/sqls/inssimple.data src/test/performance/sqls/orbsimple src/test/performance/sqls/slcsimple src/test/performance/sqls/slcsimple.data src/test/performance/sqls/vacuum src/test/performance/start-pgsql.sh src/test/regress/GNUmakefile src/test/regress/Makefile src/test/regress/README src/test/regress/data/agg.data src/test/regress/data/constrf.data src/test/regress/data/constro.data src/test/regress/data/dept.data src/test/regress/data/desc.data src/test/regress/data/emp.data src/test/regress/data/hash.data src/test/regress/data/onek.data src/test/regress/data/person.data src/test/regress/data/real_city.data src/test/regress/data/rect.data src/test/regress/data/streets.data src/test/regress/data/stud_emp.data src/test/regress/data/student.data src/test/regress/data/tenk.data src/test/regress/expected/abstime-solaris-1947.out src/test/regress/expected/abstime.out src/test/regress/expected/aggregates.out src/test/regress/expected/alter_table.out src/test/regress/expected/arrays.out src/test/regress/expected/bit.out src/test/regress/expected/boolean.out src/test/regress/expected/box.out src/test/regress/expected/btree_index.out src/test/regress/expected/case.out src/test/regress/expected/char.out src/test/regress/expected/char_1.out src/test/regress/expected/circle.out src/test/regress/expected/comments.out src/test/regress/expected/create_aggregate.out src/test/regress/expected/create_index.out src/test/regress/expected/create_misc.out src/test/regress/expected/create_operator.out src/test/regress/expected/create_table.out src/test/regress/expected/create_type.out src/test/regress/expected/create_view.out src/test/regress/expected/date.out src/test/regress/expected/domain.out src/test/regress/expected/errors.out src/test/regress/expected/euc_cn.out src/test/regress/expected/euc_jp.out src/test/regress/expected/euc_kr.out src/test/regress/expected/euc_tw.out src/test/regress/expected/float4-exp-three-digits.out src/test/regress/expected/float4.out src/test/regress/expected/float8-exp-three-digits.out src/test/regress/expected/float8-fp-exception.out src/test/regress/expected/float8-small-is-zero.out src/test/regress/expected/float8.out src/test/regress/expected/foreign_key.out src/test/regress/expected/geometry-alpha-precision.out src/test/regress/expected/geometry-bsdi-precision.out src/test/regress/expected/geometry-i86-gnulibc.out src/test/regress/expected/geometry-intel-beos.out src/test/regress/expected/geometry-irix.out src/test/regress/expected/geometry-positive-zeros-bsd.out src/test/regress/expected/geometry-positive-zeros.out src/test/regress/expected/geometry-powerpc-aix4.out src/test/regress/expected/geometry-powerpc-darwin.out src/test/regress/expected/geometry-powerpc-linux-gnulibc1.out src/test/regress/expected/geometry-solaris-i386-pc.out src/test/regress/expected/geometry-solaris-precision.out src/test/regress/expected/geometry-uw7-cc.out src/test/regress/expected/geometry-uw7-gcc.out src/test/regress/expected/geometry.out src/test/regress/expected/hash_index.out src/test/regress/expected/horology-no-DST-before-1970.out src/test/regress/expected/horology-solaris-1947.out src/test/regress/expected/horology.out src/test/regress/expected/inet.out src/test/regress/expected/inherit.out src/test/regress/expected/insert.out src/test/regress/expected/int2.out src/test/regress/expected/int4.out src/test/regress/expected/int8-exp-three-digits.out src/test/regress/expected/int8.out src/test/regress/expected/interval.out src/test/regress/expected/join.out src/test/regress/expected/limit.out src/test/regress/expected/lseg.out src/test/regress/expected/mule_internal.out src/test/regress/expected/name.out src/test/regress/expected/numeric.out src/test/regress/expected/numeric_big.out src/test/regress/expected/numerology.out src/test/regress/expected/oid.out src/test/regress/expected/oidjoins.out src/test/regress/expected/opr_sanity.out src/test/regress/expected/path.out src/test/regress/expected/plpgsql.out src/test/regress/expected/point.out src/test/regress/expected/polygon.out src/test/regress/expected/portals.out src/test/regress/expected/portals_p2.out src/test/regress/expected/privileges.out src/test/regress/expected/random.out src/test/regress/expected/reltime.out src/test/regress/expected/rules.out src/test/regress/expected/sanity_check.out src/test/regress/expected/select.out src/test/regress/expected/select_distinct.out src/test/regress/expected/select_distinct_on.out src/test/regress/expected/select_having.out src/test/regress/expected/select_having_1.out src/test/regress/expected/select_implicit.out src/test/regress/expected/select_implicit_1.out src/test/regress/expected/select_into.out src/test/regress/expected/select_views.out src/test/regress/expected/select_views_1.out src/test/regress/expected/sql_ascii.out src/test/regress/expected/strings.out src/test/regress/expected/subselect.out src/test/regress/expected/temp.out src/test/regress/expected/text.out src/test/regress/expected/time.out src/test/regress/expected/timestamp.out src/test/regress/expected/timestamptz.out src/test/regress/expected/timetz.out src/test/regress/expected/tinterval-solaris-1947.out src/test/regress/expected/tinterval.out src/test/regress/expected/transactions.out src/test/regress/expected/triggers.out src/test/regress/expected/type_sanity.out src/test/regress/expected/union.out src/test/regress/expected/varchar.out src/test/regress/expected/varchar_1.out src/test/regress/input/constraints.source src/test/regress/input/copy.source src/test/regress/input/create_function_1.source src/test/regress/input/create_function_2.source src/test/regress/input/misc.source src/test/regress/output/constraints.source src/test/regress/output/copy.source src/test/regress/output/create_function_1.source src/test/regress/output/create_function_2.source src/test/regress/output/misc.source src/test/regress/parallel_schedule src/test/regress/pg_regress.sh src/test/regress/regress.c src/test/regress/regressplans.sh src/test/regress/resultmap src/test/regress/serial_schedule src/test/regress/sql/abstime.sql src/test/regress/sql/aggregates.sql src/test/regress/sql/alter_table.sql src/test/regress/sql/arrays.sql src/test/regress/sql/bit.sql src/test/regress/sql/boolean.sql src/test/regress/sql/box.sql src/test/regress/sql/btree_index.sql src/test/regress/sql/case.sql src/test/regress/sql/char.sql src/test/regress/sql/circle.sql src/test/regress/sql/comments.sql src/test/regress/sql/create_aggregate.sql src/test/regress/sql/create_index.sql src/test/regress/sql/create_misc.sql src/test/regress/sql/create_operator.sql src/test/regress/sql/create_table.sql src/test/regress/sql/create_type.sql src/test/regress/sql/create_view.sql src/test/regress/sql/date.sql src/test/regress/sql/domain.sql src/test/regress/sql/drop.sql src/test/regress/sql/errors.sql src/test/regress/sql/euc_cn.sql src/test/regress/sql/euc_jp.sql src/test/regress/sql/euc_kr.sql src/test/regress/sql/euc_tw.sql src/test/regress/sql/float4.sql src/test/regress/sql/float8.sql src/test/regress/sql/foreign_key.sql src/test/regress/sql/geometry.sql src/test/regress/sql/hash_index.sql src/test/regress/sql/horology.sql src/test/regress/sql/inet.sql src/test/regress/sql/inherit.sql src/test/regress/sql/insert.sql src/test/regress/sql/int2.sql src/test/regress/sql/int4.sql src/test/regress/sql/int8.sql src/test/regress/sql/interval.sql src/test/regress/sql/join.sql src/test/regress/sql/limit.sql src/test/regress/sql/lseg.sql src/test/regress/sql/mule_internal.sql src/test/regress/sql/name.sql src/test/regress/sql/numeric.sql src/test/regress/sql/numeric_big.sql src/test/regress/sql/numerology.sql src/test/regress/sql/oid.sql src/test/regress/sql/oidjoins.sql src/test/regress/sql/opr_sanity.sql src/test/regress/sql/path.sql src/test/regress/sql/plpgsql.sql src/test/regress/sql/point.sql src/test/regress/sql/polygon.sql src/test/regress/sql/portals.sql src/test/regress/sql/portals_p2.sql src/test/regress/sql/privileges.sql src/test/regress/sql/random.sql src/test/regress/sql/reltime.sql src/test/regress/sql/rules.sql src/test/regress/sql/sanity_check.sql src/test/regress/sql/select.sql src/test/regress/sql/select_distinct.sql src/test/regress/sql/select_distinct_on.sql src/test/regress/sql/select_having.sql src/test/regress/sql/select_implicit.sql src/test/regress/sql/select_into.sql src/test/regress/sql/select_views.sql src/test/regress/sql/sql_ascii.sql src/test/regress/sql/strings.sql src/test/regress/sql/subselect.sql src/test/regress/sql/temp.sql src/test/regress/sql/text.sql src/test/regress/sql/time.sql src/test/regress/sql/timestamp.sql src/test/regress/sql/timestamptz.sql src/test/regress/sql/timetz.sql src/test/regress/sql/tinterval.sql src/test/regress/sql/transactions.sql src/test/regress/sql/triggers.sql src/test/regress/sql/type_sanity.sql src/test/regress/sql/union.sql src/test/regress/sql/varchar.sql src/tools/RELEASE_CHANGES src/tools/backend/README src/tools/backend/backend_dirs.html src/tools/backend/flow.fig src/tools/backend/flow.gif src/tools/backend/index.html src/tools/ccsym src/tools/copyright src/tools/entab/Makefile src/tools/entab/entab.c src/tools/entab/entab.man src/tools/entab/halt.c src/tools/find_badmacros src/tools/find_static src/tools/find_typedef src/tools/make_ctags src/tools/make_diff/README src/tools/make_diff/cporig src/tools/make_diff/difforig src/tools/make_diff/rmorig src/tools/make_etags src/tools/make_keywords src/tools/make_mkid src/tools/pgcvslog src/tools/pginclude/README src/tools/pginclude/pgcompinclude src/tools/pginclude/pgdefine src/tools/pginclude/pgfixinclude src/tools/pginclude/pgrminclude src/tools/pgindent/README src/tools/pgindent/indent.bsd.patch src/tools/pgindent/pgcppindent src/tools/pgindent/pgindent src/tools/pgindent/pgjindent src/tutorial/Makefile src/tutorial/README src/tutorial/advanced.source src/tutorial/basics.source src/tutorial/beard.c src/tutorial/complex.c src/tutorial/complex.source src/tutorial/funcs.c src/tutorial/funcs.source src/tutorial/funcs_new.c src/tutorial/syscat.source src/utils/Makefile src/utils/README src/utils/dllinit.c src/utils/getopt.c src/utils/strdup.c src/win32.mak
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/.cvsignore3
-rw-r--r--src/backend/parser/Makefile63
-rw-r--r--src/backend/parser/README20
-rw-r--r--src/backend/parser/analyze.c3260
-rw-r--r--src/backend/parser/gram.y7218
-rw-r--r--src/backend/parser/keywords.c384
-rw-r--r--src/backend/parser/parse_agg.c180
-rw-r--r--src/backend/parser/parse_clause.c1405
-rw-r--r--src/backend/parser/parse_coerce.c807
-rw-r--r--src/backend/parser/parse_expr.c1170
-rw-r--r--src/backend/parser/parse_func.c1387
-rw-r--r--src/backend/parser/parse_node.c514
-rw-r--r--src/backend/parser/parse_oper.c935
-rw-r--r--src/backend/parser/parse_relation.c1451
-rw-r--r--src/backend/parser/parse_target.c561
-rw-r--r--src/backend/parser/parse_type.c505
-rw-r--r--src/backend/parser/parser.c110
-rw-r--r--src/backend/parser/scan.l666
-rw-r--r--src/backend/parser/scansup.c111
19 files changed, 0 insertions, 20750 deletions
diff --git a/src/backend/parser/.cvsignore b/src/backend/parser/.cvsignore
deleted file mode 100644
index 84c828f3bf4..00000000000
--- a/src/backend/parser/.cvsignore
+++ /dev/null
@@ -1,3 +0,0 @@
-parse.h
-gram.c
-scan.c
diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile
deleted file mode 100644
index d5d4f4372d8..00000000000
--- a/src/backend/parser/Makefile
+++ /dev/null
@@ -1,63 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile for parser
-#
-# $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.37 2002/04/20 21:56:14 petere Exp $
-#
-#-------------------------------------------------------------------------
-
-subdir = src/backend/parser
-top_builddir = ../../..
-include $(top_builddir)/src/Makefile.global
-
-OBJS= analyze.o gram.o keywords.o parser.o parse_agg.o parse_clause.o \
- parse_expr.o parse_func.o parse_node.o parse_oper.o parse_relation.o \
- parse_type.o parse_coerce.o parse_target.o scan.o scansup.o
-
-FLEXFLAGS = -CF
-
-
-all: SUBSYS.o
-
-SUBSYS.o: $(OBJS)
- $(LD) $(LDREL) $(LDOUT) $@ $^
-
-
-# There is no correct way to write a rule that generates two files.
-# Rules with two targets don't have that meaning, they are merely
-# shorthand for two otherwise separate rules. To be safe for parallel
-# make, we must chain the dependencies like this. The semicolon is
-# important, otherwise make will choose the built-in rule for
-# gram.y=>gram.c.
-
-$(srcdir)/gram.c: $(srcdir)/parse.h ;
-
-$(srcdir)/parse.h: gram.y
-ifdef YACC
- $(YACC) -d $(YFLAGS) $<
- mv -f y.tab.c $(srcdir)/gram.c
- mv -f y.tab.h $(srcdir)/parse.h
-else
- @$(missing) bison $< $@
-endif
-
-
-$(srcdir)/scan.c: scan.l
-ifdef FLEX
- $(FLEX) $(FLEXFLAGS) -o'$@' $<
-else
- @$(missing) flex $< $@
-endif
-
-
-# Force these dependencies to be known even without dependency info built:
-
-keywords.o parse_clause.o parse_expr.o parser.o scan.o: $(srcdir)/parse.h
-
-
-# gram.c, parse.h, and scan.c are in the distribution tarball, so they
-# are not cleaned here.
-clean:
- rm -f SUBSYS.o $(OBJS)
-# And the garbage that might have been left behind by partial build:
- @rm -f y.tab.c y.tab.h lex.yy.c
diff --git a/src/backend/parser/README b/src/backend/parser/README
deleted file mode 100644
index effa9008fa9..00000000000
--- a/src/backend/parser/README
+++ /dev/null
@@ -1,20 +0,0 @@
-This directory does more than tokenize and parse SQL queries. It also
-creates Query structures for the various complex queries that is passed
-to the optimizer and then executor.
-
-parser.c things start here
-scan.l break query into tokens
-scansup.c handle escapes in input
-keywords.c turn keywords into specific tokens
-gram.y parse the tokens and fill query-type-specific structures
-analyze.c handle post-parse processing for each query type
-parse_clause.c handle clauses like WHERE, ORDER BY, GROUP BY, ...
-parse_coerce.c used for coercing expressions of different types
-parse_expr.c handle expressions like col, col + 3, x = 3 or x = 4
-parse_oper.c handle operations in expressions
-parse_agg.c handle aggregates, like SUM(col1), AVG(col2), ...
-parse_func.c handle functions, table.column and column identifiers
-parse_node.c create nodes for various structures
-parse_target.c handle the result list of the query
-parse_relation.c support routines for tables and column handling
-parse_type.c support routines for type handling
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
deleted file mode 100644
index b1b94dc6fda..00000000000
--- a/src/backend/parser/analyze.c
+++ /dev/null
@@ -1,3260 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * analyze.c
- * transform the parse tree into a query tree
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.237 2002/06/20 20:29:31 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "access/heapam.h"
-#include "catalog/catname.h"
-#include "catalog/heap.h"
-#include "catalog/index.h"
-#include "catalog/namespace.h"
-#include "catalog/pg_index.h"
-#include "catalog/pg_type.h"
-#include "nodes/makefuncs.h"
-#include "parser/analyze.h"
-#include "parser/gramparse.h"
-#include "parser/parsetree.h"
-#include "parser/parse_agg.h"
-#include "parser/parse_clause.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_oper.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_target.h"
-#include "parser/parse_type.h"
-#include "parser/parse_expr.h"
-#include "rewrite/rewriteManip.h"
-#include "utils/builtins.h"
-#include "utils/fmgroids.h"
-#include "utils/lsyscache.h"
-#include "utils/relcache.h"
-#include "utils/syscache.h"
-#ifdef MULTIBYTE
-#include "mb/pg_wchar.h"
-#endif
-
-
-/* State shared by transformCreateSchemaStmt and its subroutines */
-typedef struct
-{
- const char *stmtType; /* "CREATE TABLE" or "ALTER TABLE" */
- char *schemaname; /* name of schema */
- char *authid; /* owner of schema */
- List *tables; /* CREATE TABLE items */
- List *views; /* CREATE VIEW items */
- List *grants; /* GRANT items */
- List *fwconstraints; /* Forward referencing FOREIGN KEY constraints */
- List *alters; /* Generated ALTER items (from the above) */
- List *ixconstraints; /* index-creating constraints */
- List *blist; /* "before list" of things to do before
- * creating the schema */
- List *alist; /* "after list" of things to do after
- * creating the schema */
-} CreateSchemaStmtContext;
-
-/* State shared by transformCreateStmt and its subroutines */
-typedef struct
-{
- const char *stmtType; /* "CREATE TABLE" or "ALTER TABLE" */
- RangeVar *relation; /* relation to create */
- List *inhRelations; /* relations to inherit from */
- bool hasoids; /* does relation have an OID column? */
- Oid relOid; /* OID of table, if ALTER TABLE case */
- List *columns; /* ColumnDef items */
- List *ckconstraints; /* CHECK constraints */
- List *fkconstraints; /* FOREIGN KEY constraints */
- List *ixconstraints; /* index-creating constraints */
- List *blist; /* "before list" of things to do before
- * creating the table */
- List *alist; /* "after list" of things to do after
- * creating the table */
- IndexStmt *pkey; /* PRIMARY KEY index, if any */
-} CreateStmtContext;
-
-
-static Query *transformStmt(ParseState *pstate, Node *stmt,
- List **extras_before, List **extras_after);
-static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt);
-static Query *transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
- List **extras_before, List **extras_after);
-static Query *transformIndexStmt(ParseState *pstate, IndexStmt *stmt);
-static Query *transformRuleStmt(ParseState *query, RuleStmt *stmt,
- List **extras_before, List **extras_after);
-static Query *transformSelectStmt(ParseState *pstate, SelectStmt *stmt);
-static Query *transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt);
-static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt);
-static Query *transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt);
-static Query *transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
- List **extras_before, List **extras_after);
-static Query *transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
- List **extras_before, List **extras_after);
-static void transformColumnDefinition(ParseState *pstate,
- CreateStmtContext *cxt,
- ColumnDef *column);
-static void transformTableConstraint(ParseState *pstate,
- CreateStmtContext *cxt,
- Constraint *constraint);
-static void transformIndexConstraints(ParseState *pstate,
- CreateStmtContext *cxt);
-static void transformFKConstraints(ParseState *pstate,
- CreateStmtContext *cxt);
-static void applyColumnNames(List *dst, List *src);
-static List *getSetColTypes(ParseState *pstate, Node *node);
-static void transformForUpdate(Query *qry, List *forUpdate);
-static void transformConstraintAttrs(List *constraintList);
-static void transformColumnType(ParseState *pstate, ColumnDef *column);
-static void transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid);
-static void transformFkeyGetPrimaryKey(FkConstraint *fkconstraint, Oid *pktypoid);
-static bool relationHasPrimaryKey(Oid relationOid);
-static Oid transformFkeyGetColType(CreateStmtContext *cxt, char *colname);
-static void release_pstate_resources(ParseState *pstate);
-static FromExpr *makeFromExpr(List *fromlist, Node *quals);
-
-
-
-/*
- * parse_analyze -
- * analyze a raw parse tree and transform it to Query form.
- *
- * The result is a List of Query nodes (we need a list since some commands
- * produce multiple Queries). Optimizable statements require considerable
- * transformation, while many utility-type statements are simply hung off
- * a dummy CMD_UTILITY Query node.
- */
-List *
-parse_analyze(Node *parseTree, ParseState *parentParseState)
-{
- List *result = NIL;
- ParseState *pstate = make_parsestate(parentParseState);
- /* Lists to return extra commands from transformation */
- List *extras_before = NIL;
- List *extras_after = NIL;
- Query *query;
- List *listscan;
-
- query = transformStmt(pstate, parseTree, &extras_before, &extras_after);
- release_pstate_resources(pstate);
-
- while (extras_before != NIL)
- {
- result = nconc(result, parse_analyze(lfirst(extras_before), pstate));
- extras_before = lnext(extras_before);
- }
-
- result = lappend(result, query);
-
- while (extras_after != NIL)
- {
- result = nconc(result, parse_analyze(lfirst(extras_after), pstate));
- extras_after = lnext(extras_after);
- }
-
- /*
- * Make sure that only the original query is marked original.
- * We have to do this explicitly since recursive calls of parse_analyze
- * will have set originalQuery in some of the added-on queries.
- */
- foreach(listscan, result)
- {
- Query *q = lfirst(listscan);
-
- q->originalQuery = (q == query);
- }
-
- pfree(pstate);
-
- return result;
-}
-
-static void
-release_pstate_resources(ParseState *pstate)
-{
- if (pstate->p_target_relation != NULL)
- heap_close(pstate->p_target_relation, NoLock);
- pstate->p_target_relation = NULL;
- pstate->p_target_rangetblentry = NULL;
-}
-
-/*
- * transformStmt -
- * transform a Parse tree into a Query tree.
- */
-static Query *
-transformStmt(ParseState *pstate, Node *parseTree,
- List **extras_before, List **extras_after)
-{
- Query *result = NULL;
-
- switch (nodeTag(parseTree))
- {
- /*
- * Non-optimizable statements
- */
- case T_CreateStmt:
- result = transformCreateStmt(pstate, (CreateStmt *) parseTree,
- extras_before, extras_after);
- break;
-
- case T_IndexStmt:
- result = transformIndexStmt(pstate, (IndexStmt *) parseTree);
- break;
-
- case T_RuleStmt:
- result = transformRuleStmt(pstate, (RuleStmt *) parseTree,
- extras_before, extras_after);
- break;
-
- case T_ViewStmt:
- {
- ViewStmt *n = (ViewStmt *) parseTree;
-
- n->query = transformStmt(pstate, (Node *) n->query,
- extras_before, extras_after);
-
- /*
- * If a list of column names was given, run through and
- * insert these into the actual query tree. - thomas
- * 2000-03-08
- *
- * Outer loop is over targetlist to make it easier to skip
- * junk targetlist entries.
- */
- if (n->aliases != NIL)
- {
- List *aliaslist = n->aliases;
- List *targetList;
-
- foreach(targetList, n->query->targetList)
- {
- TargetEntry *te = (TargetEntry *) lfirst(targetList);
- Resdom *rd;
- Ident *id;
-
- Assert(IsA(te, TargetEntry));
- rd = te->resdom;
- Assert(IsA(rd, Resdom));
- if (rd->resjunk) /* junk columns don't get
- * aliases */
- continue;
- id = (Ident *) lfirst(aliaslist);
- Assert(IsA(id, Ident));
- rd->resname = pstrdup(id->name);
- aliaslist = lnext(aliaslist);
- if (aliaslist == NIL)
- break; /* done assigning aliases */
- }
-
- if (aliaslist != NIL)
- elog(ERROR, "CREATE VIEW specifies more column names than columns");
- }
- result = makeNode(Query);
- result->commandType = CMD_UTILITY;
- result->utilityStmt = (Node *) n;
- }
- break;
-
- case T_ExplainStmt:
- {
- ExplainStmt *n = (ExplainStmt *) parseTree;
-
- result = makeNode(Query);
- result->commandType = CMD_UTILITY;
- n->query = transformStmt(pstate, (Node *) n->query,
- extras_before, extras_after);
- result->utilityStmt = (Node *) parseTree;
- }
- break;
-
- case T_AlterTableStmt:
- result = transformAlterTableStmt(pstate, (AlterTableStmt *) parseTree,
- extras_before, extras_after);
- break;
-
- /*
- * Optimizable statements
- */
- case T_InsertStmt:
- result = transformInsertStmt(pstate, (InsertStmt *) parseTree,
- extras_before, extras_after);
- break;
-
- case T_DeleteStmt:
- result = transformDeleteStmt(pstate, (DeleteStmt *) parseTree);
- break;
-
- case T_UpdateStmt:
- result = transformUpdateStmt(pstate, (UpdateStmt *) parseTree);
- break;
-
- case T_SelectStmt:
- if (((SelectStmt *) parseTree)->op == SETOP_NONE)
- result = transformSelectStmt(pstate,
- (SelectStmt *) parseTree);
- else
- result = transformSetOperationStmt(pstate,
- (SelectStmt *) parseTree);
- break;
-
- default:
-
- /*
- * other statements don't require any transformation-- just
- * return the original parsetree, yea!
- */
- result = makeNode(Query);
- result->commandType = CMD_UTILITY;
- result->utilityStmt = (Node *) parseTree;
- break;
- }
- return result;
-}
-
-/*
- * transformDeleteStmt -
- * transforms a Delete Statement
- */
-static Query *
-transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
-{
- Query *qry = makeNode(Query);
- Node *qual;
-
- qry->commandType = CMD_DELETE;
-
- /* set up range table with just the result rel */
- qry->resultRelation = setTargetTable(pstate, stmt->relation,
- interpretInhOption(stmt->relation->inhOpt),
- true);
-
- qry->distinctClause = NIL;
-
- /* fix where clause */
- qual = transformWhereClause(pstate, stmt->whereClause);
-
- /* done building the range table and jointree */
- qry->rtable = pstate->p_rtable;
- qry->jointree = makeFromExpr(pstate->p_joinlist, qual);
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- qry->hasAggs = pstate->p_hasAggs;
- if (pstate->p_hasAggs)
- parseCheckAggregates(pstate, qry, qual);
-
- return qry;
-}
-
-/*
- * transformInsertStmt -
- * transform an Insert Statement
- */
-static Query *
-transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
- List **extras_before, List **extras_after)
-{
- Query *qry = makeNode(Query);
- List *sub_rtable;
- List *sub_namespace;
- List *icolumns;
- List *attrnos;
- List *attnos;
- List *tl;
-
- qry->commandType = CMD_INSERT;
- pstate->p_is_insert = true;
-
- /*
- * If a non-nil rangetable/namespace was passed in, and we are doing
- * INSERT/SELECT, arrange to pass the rangetable/namespace down to the
- * SELECT. This can only happen if we are inside a CREATE RULE, and
- * in that case we want the rule's OLD and NEW rtable entries to
- * appear as part of the SELECT's rtable, not as outer references for
- * it. (Kluge!) The SELECT's joinlist is not affected however. We
- * must do this before adding the target table to the INSERT's rtable.
- */
- if (stmt->selectStmt)
- {
- sub_rtable = pstate->p_rtable;
- pstate->p_rtable = NIL;
- sub_namespace = pstate->p_namespace;
- pstate->p_namespace = NIL;
- }
- else
- {
- sub_rtable = NIL; /* not used, but keep compiler quiet */
- sub_namespace = NIL;
- }
-
- /*
- * Must get write lock on INSERT target table before scanning SELECT,
- * else we will grab the wrong kind of initial lock if the target
- * table is also mentioned in the SELECT part. Note that the target
- * table is not added to the joinlist or namespace.
- */
- qry->resultRelation = setTargetTable(pstate, stmt->relation,
- false, false);
-
- /*
- * Is it INSERT ... SELECT or INSERT ... VALUES?
- */
- if (stmt->selectStmt)
- {
- ParseState *sub_pstate = make_parsestate(pstate->parentParseState);
- Query *selectQuery;
- RangeTblEntry *rte;
- RangeTblRef *rtr;
-
- /*
- * Process the source SELECT.
- *
- * It is important that this be handled just like a standalone
- * SELECT; otherwise the behavior of SELECT within INSERT might be
- * different from a stand-alone SELECT. (Indeed, Postgres up
- * through 6.5 had bugs of just that nature...)
- */
- sub_pstate->p_rtable = sub_rtable;
- sub_pstate->p_namespace = sub_namespace;
-
- /*
- * Note: we are not expecting that extras_before and extras_after
- * are going to be used by the transformation of the SELECT statement.
- */
- selectQuery = transformStmt(sub_pstate, stmt->selectStmt,
- extras_before, extras_after);
-
- release_pstate_resources(sub_pstate);
- pfree(sub_pstate);
-
- Assert(IsA(selectQuery, Query));
- Assert(selectQuery->commandType == CMD_SELECT);
- if (selectQuery->into || selectQuery->isPortal)
- elog(ERROR, "INSERT ... SELECT may not specify INTO");
-
- /*
- * Make the source be a subquery in the INSERT's rangetable, and
- * add it to the INSERT's joinlist.
- */
- rte = addRangeTableEntryForSubquery(pstate,
- selectQuery,
- makeAlias("*SELECT*", NIL),
- true);
- rtr = makeNode(RangeTblRef);
- /* assume new rte is at end */
- rtr->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtr->rtindex, pstate->p_rtable));
- pstate->p_joinlist = lappend(pstate->p_joinlist, rtr);
-
- /*
- * Generate a targetlist for the INSERT that selects all the
- * non-resjunk columns from the subquery. (We need this to be
- * separate from the subquery's tlist because we may add columns,
- * insert datatype coercions, etc.)
- *
- * HACK: constants in the INSERT's targetlist are copied up as-is
- * rather than being referenced as subquery outputs. This is
- * mainly to ensure that when we try to coerce them to the target
- * column's datatype, the right things happen for UNKNOWN
- * constants. Otherwise this fails: INSERT INTO foo SELECT 'bar',
- * ... FROM baz
- */
- qry->targetList = NIL;
- foreach(tl, selectQuery->targetList)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Resdom *resnode = tle->resdom;
- Node *expr;
-
- if (resnode->resjunk)
- continue;
- if (tle->expr && IsA(tle->expr, Const))
- expr = tle->expr;
- else
- expr = (Node *) makeVar(rtr->rtindex,
- resnode->resno,
- resnode->restype,
- resnode->restypmod,
- 0);
- resnode = copyObject(resnode);
- resnode->resno = (AttrNumber) pstate->p_last_resno++;
- qry->targetList = lappend(qry->targetList,
- makeTargetEntry(resnode, expr));
- }
- }
- else
- {
- /*
- * For INSERT ... VALUES, transform the given list of values to
- * form a targetlist for the INSERT.
- */
- qry->targetList = transformTargetList(pstate, stmt->targetList);
- }
-
- /*
- * Now we are done with SELECT-like processing, and can get on with
- * transforming the target list to match the INSERT target columns.
- */
-
- /* Prepare to assign non-conflicting resnos to resjunk attributes */
- if (pstate->p_last_resno <= pstate->p_target_relation->rd_rel->relnatts)
- pstate->p_last_resno = pstate->p_target_relation->rd_rel->relnatts + 1;
-
- /* Validate stmt->cols list, or build default list if no list given */
- icolumns = checkInsertTargets(pstate, stmt->cols, &attrnos);
-
- /*
- * Prepare columns for assignment to target table.
- */
- attnos = attrnos;
- foreach(tl, qry->targetList)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- ResTarget *col;
-
- if (icolumns == NIL || attnos == NIL)
- elog(ERROR, "INSERT has more expressions than target columns");
- col = (ResTarget *) lfirst(icolumns);
-
- /*
- * When the value is to be set to the column default we can simply
- * drop it now and handle it later on using methods for missing
- * columns.
- */
- if (!IsA(tle, InsertDefault))
- {
- Assert(IsA(col, ResTarget));
- Assert(!tle->resdom->resjunk);
- updateTargetListEntry(pstate, tle, col->name, lfirsti(attnos),
- col->indirection);
- }
- else
- {
- icolumns = lremove(icolumns, icolumns);
- attnos = lremove(attnos, attnos);
- qry->targetList = lremove(tle, qry->targetList);
- }
-
- icolumns = lnext(icolumns);
- attnos = lnext(attnos);
- }
-
- /*
- * Ensure that the targetlist has the same number of entries
- * that were present in the columns list. Don't do the check
- * for select statements.
- */
- if (stmt->cols != NIL && (icolumns != NIL || attnos != NIL))
- elog(ERROR, "INSERT has more target columns than expressions");
-
- /* done building the range table and jointree */
- qry->rtable = pstate->p_rtable;
- qry->jointree = makeFromExpr(pstate->p_joinlist, NULL);
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- qry->hasAggs = pstate->p_hasAggs;
- if (pstate->p_hasAggs)
- parseCheckAggregates(pstate, qry, NULL);
-
- return qry;
-}
-
-/*
- * makeObjectName()
- *
- * Create a name for an implicitly created index, sequence, constraint, etc.
- *
- * The parameters are: the original table name, the original field name, and
- * a "type" string (such as "seq" or "pkey"). The field name and/or type
- * can be NULL if not relevant.
- *
- * The result is a palloc'd string.
- *
- * The basic result we want is "name1_name2_type", omitting "_name2" or
- * "_type" when those parameters are NULL. However, we must generate
- * a name with less than NAMEDATALEN characters! So, we truncate one or
- * both names if necessary to make a short-enough string. The type part
- * is never truncated (so it had better be reasonably short).
- *
- * To reduce the probability of collisions, we might someday add more
- * smarts to this routine, like including some "hash" characters computed
- * from the truncated characters. Currently it seems best to keep it simple,
- * so that the generated names are easily predictable by a person.
- */
-char *
-makeObjectName(char *name1, char *name2, char *typename)
-{
- char *name;
- int overhead = 0; /* chars needed for type and underscores */
- int availchars; /* chars available for name(s) */
- int name1chars; /* chars allocated to name1 */
- int name2chars; /* chars allocated to name2 */
- int ndx;
-
- name1chars = strlen(name1);
- if (name2)
- {
- name2chars = strlen(name2);
- overhead++; /* allow for separating underscore */
- }
- else
- name2chars = 0;
- if (typename)
- overhead += strlen(typename) + 1;
-
- availchars = NAMEDATALEN - 1 - overhead;
-
- /*
- * If we must truncate, preferentially truncate the longer name. This
- * logic could be expressed without a loop, but it's simple and
- * obvious as a loop.
- */
- while (name1chars + name2chars > availchars)
- {
- if (name1chars > name2chars)
- name1chars--;
- else
- name2chars--;
- }
-
-#ifdef MULTIBYTE
- if (name1)
- name1chars = pg_mbcliplen(name1, name1chars, name1chars);
- if (name2)
- name2chars = pg_mbcliplen(name2, name2chars, name2chars);
-#endif
-
- /* Now construct the string using the chosen lengths */
- name = palloc(name1chars + name2chars + overhead + 1);
- strncpy(name, name1, name1chars);
- ndx = name1chars;
- if (name2)
- {
- name[ndx++] = '_';
- strncpy(name + ndx, name2, name2chars);
- ndx += name2chars;
- }
- if (typename)
- {
- name[ndx++] = '_';
- strcpy(name + ndx, typename);
- }
- else
- name[ndx] = '\0';
-
- return name;
-}
-
-static char *
-CreateIndexName(char *table_name, char *column_name,
- char *label, List *indices)
-{
- int pass = 0;
- char *iname = NULL;
- List *ilist;
- char typename[NAMEDATALEN];
-
- /*
- * The type name for makeObjectName is label, or labelN if that's
- * necessary to prevent collisions among multiple indexes for the same
- * table. Note there is no check for collisions with already-existing
- * indexes, only among the indexes we're about to create now; this
- * ought to be improved someday.
- */
- strcpy(typename, label);
-
- for (;;)
- {
- iname = makeObjectName(table_name, column_name, typename);
-
- foreach(ilist, indices)
- {
- IndexStmt *index = lfirst(ilist);
-
- if (index->idxname != NULL &&
- strcmp(iname, index->idxname) == 0)
- break;
- }
- /* ran through entire list? then no name conflict found so done */
- if (ilist == NIL)
- break;
-
- /* found a conflict, so try a new name component */
- pfree(iname);
- sprintf(typename, "%s%d", label, ++pass);
- }
-
- return iname;
-}
-
-/*
- * transformCreateStmt -
- * transforms the "create table" statement
- * SQL92 allows constraints to be scattered all over, so thumb through
- * the columns and collect all constraints into one place.
- * If there are any implied indices (e.g. UNIQUE or PRIMARY KEY)
- * then expand those into multiple IndexStmt blocks.
- * - thomas 1997-12-02
- */
-static Query *
-transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
- List **extras_before, List **extras_after)
-{
- CreateStmtContext cxt;
- Query *q;
- List *elements;
-
- cxt.stmtType = "CREATE TABLE";
- cxt.relation = stmt->relation;
- cxt.inhRelations = stmt->inhRelations;
- cxt.hasoids = stmt->hasoids;
- cxt.relOid = InvalidOid;
- cxt.columns = NIL;
- cxt.ckconstraints = NIL;
- cxt.fkconstraints = NIL;
- cxt.ixconstraints = NIL;
- cxt.blist = NIL;
- cxt.alist = NIL;
- cxt.pkey = NULL;
-
- /*
- * Run through each primary element in the table creation clause.
- * Separate column defs from constraints, and do preliminary analysis.
- */
- foreach(elements, stmt->tableElts)
- {
- Node *element = lfirst(elements);
-
- switch (nodeTag(element))
- {
- case T_ColumnDef:
- transformColumnDefinition(pstate, &cxt,
- (ColumnDef *) element);
- break;
-
- case T_Constraint:
- transformTableConstraint(pstate, &cxt,
- (Constraint *) element);
- break;
-
- case T_FkConstraint:
- /* No pre-transformation needed */
- cxt.fkconstraints = lappend(cxt.fkconstraints, element);
- break;
-
- default:
- elog(ERROR, "parser: unrecognized node (internal error)");
- }
- }
-
- Assert(stmt->constraints == NIL);
-
- /*
- * Postprocess constraints that give rise to index definitions.
- */
- transformIndexConstraints(pstate, &cxt);
-
- /*
- * Postprocess foreign-key constraints.
- */
- transformFKConstraints(pstate, &cxt);
-
- /*
- * Output results.
- */
- q = makeNode(Query);
- q->commandType = CMD_UTILITY;
- q->utilityStmt = (Node *) stmt;
- stmt->tableElts = cxt.columns;
- stmt->constraints = cxt.ckconstraints;
- *extras_before = nconc (*extras_before, cxt.blist);
- *extras_after = nconc (cxt.alist, *extras_after);
-
- return q;
-}
-
-static void
-transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
- ColumnDef *column)
-{
- bool is_serial;
- bool saw_nullable;
- Constraint *constraint;
- List *clist;
- Ident *key;
-
- cxt->columns = lappend(cxt->columns, column);
-
- /* Check for SERIAL pseudo-types */
- is_serial = false;
- if (length(column->typename->names) == 1)
- {
- char *typname = strVal(lfirst(column->typename->names));
-
- if (strcmp(typname, "serial") == 0 ||
- strcmp(typname, "serial4") == 0)
- {
- is_serial = true;
- column->typename->names = NIL;
- column->typename->typeid = INT4OID;
- }
- else if (strcmp(typname, "bigserial") == 0 ||
- strcmp(typname, "serial8") == 0)
- {
- is_serial = true;
- column->typename->names = NIL;
- column->typename->typeid = INT8OID;
- }
- }
-
- /* Do necessary work on the column type declaration */
- transformColumnType(pstate, column);
-
- /* Special actions for SERIAL pseudo-types */
- if (is_serial)
- {
- char *sname;
- char *snamespace;
- char *qstring;
- A_Const *snamenode;
- FuncCall *funccallnode;
- CreateSeqStmt *seqstmt;
-
- /*
- * Determine name and namespace to use for the sequence.
- */
- sname = makeObjectName(cxt->relation->relname, column->colname, "seq");
- snamespace = get_namespace_name(RangeVarGetCreationNamespace(cxt->relation));
-
- elog(NOTICE, "%s will create implicit sequence '%s' for SERIAL column '%s.%s'",
- cxt->stmtType, sname, cxt->relation->relname, column->colname);
-
- /*
- * Build a CREATE SEQUENCE command to create the sequence object,
- * and add it to the list of things to be done before this
- * CREATE/ALTER TABLE.
- */
- seqstmt = makeNode(CreateSeqStmt);
- seqstmt->sequence = makeRangeVar(snamespace, sname);
- seqstmt->options = NIL;
-
- cxt->blist = lappend(cxt->blist, seqstmt);
-
- /*
- * Create appropriate constraints for SERIAL. We do this in full,
- * rather than shortcutting, so that we will detect any
- * conflicting constraints the user wrote (like a different
- * DEFAULT).
- *
- * Create an expression tree representing the function call
- * nextval('"sequencename"')
- */
- qstring = quote_qualified_identifier(snamespace, sname);
- snamenode = makeNode(A_Const);
- snamenode->val.type = T_String;
- snamenode->val.val.str = qstring;
- funccallnode = makeNode(FuncCall);
- funccallnode->funcname = SystemFuncName("nextval");
- funccallnode->args = makeList1(snamenode);
- funccallnode->agg_star = false;
- funccallnode->agg_distinct = false;
-
- constraint = makeNode(Constraint);
- constraint->contype = CONSTR_DEFAULT;
- constraint->name = sname;
- constraint->raw_expr = (Node *) funccallnode;
- constraint->cooked_expr = NULL;
- constraint->keys = NIL;
- column->constraints = lappend(column->constraints, constraint);
-
- constraint = makeNode(Constraint);
- constraint->contype = CONSTR_UNIQUE;
- constraint->name = NULL; /* assign later */
- column->constraints = lappend(column->constraints, constraint);
-
- constraint = makeNode(Constraint);
- constraint->contype = CONSTR_NOTNULL;
- column->constraints = lappend(column->constraints, constraint);
- }
-
- /* Process column constraints, if any... */
- transformConstraintAttrs(column->constraints);
-
- saw_nullable = false;
-
- foreach(clist, column->constraints)
- {
- constraint = lfirst(clist);
-
- /*
- * If this column constraint is a FOREIGN KEY constraint, then we
- * fill in the current attributes name and throw it into the list
- * of FK constraints to be processed later.
- */
- if (IsA(constraint, FkConstraint))
- {
- FkConstraint *fkconstraint = (FkConstraint *) constraint;
- Ident *id = makeNode(Ident);
-
- id->name = column->colname;
- fkconstraint->fk_attrs = makeList1(id);
-
- cxt->fkconstraints = lappend(cxt->fkconstraints, fkconstraint);
- continue;
- }
-
- Assert(IsA(constraint, Constraint));
-
- switch (constraint->contype)
- {
- case CONSTR_NULL:
- if (saw_nullable && column->is_not_null)
- elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
- cxt->stmtType, (cxt->relation)->relname, column->colname);
- column->is_not_null = FALSE;
- saw_nullable = true;
- break;
-
- case CONSTR_NOTNULL:
- if (saw_nullable && !column->is_not_null)
- elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
- cxt->stmtType, (cxt->relation)->relname, column->colname);
- column->is_not_null = TRUE;
- saw_nullable = true;
- break;
-
- case CONSTR_DEFAULT:
- if (column->raw_default != NULL)
- elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'",
- cxt->stmtType, (cxt->relation)->relname, column->colname);
- column->raw_default = constraint->raw_expr;
- Assert(constraint->cooked_expr == NULL);
- break;
-
- case CONSTR_PRIMARY:
- if (constraint->name == NULL)
- constraint->name = makeObjectName((cxt->relation)->relname,
- NULL,
- "pkey");
- if (constraint->keys == NIL)
- {
- key = makeNode(Ident);
- key->name = pstrdup(column->colname);
- constraint->keys = makeList1(key);
- }
- cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
- break;
-
- case CONSTR_UNIQUE:
- if (constraint->name == NULL)
- constraint->name = makeObjectName((cxt->relation)->relname,
- column->colname,
- "key");
- if (constraint->keys == NIL)
- {
- key = makeNode(Ident);
- key->name = pstrdup(column->colname);
- constraint->keys = makeList1(key);
- }
- cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
- break;
-
- case CONSTR_CHECK:
- if (constraint->name == NULL)
- constraint->name = makeObjectName((cxt->relation)->relname,
- column->colname,
- NULL);
- cxt->ckconstraints = lappend(cxt->ckconstraints, constraint);
- break;
-
- case CONSTR_ATTR_DEFERRABLE:
- case CONSTR_ATTR_NOT_DEFERRABLE:
- case CONSTR_ATTR_DEFERRED:
- case CONSTR_ATTR_IMMEDIATE:
- /* transformConstraintAttrs took care of these */
- break;
-
- default:
- elog(ERROR, "parser: unrecognized constraint (internal error)");
- break;
- }
- }
-}
-
-static void
-transformTableConstraint(ParseState *pstate, CreateStmtContext *cxt,
- Constraint *constraint)
-{
- switch (constraint->contype)
- {
- case CONSTR_PRIMARY:
- if (constraint->name == NULL)
- constraint->name = makeObjectName((cxt->relation)->relname,
- NULL,
- "pkey");
- cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
- break;
-
- case CONSTR_UNIQUE:
- cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
- break;
-
- case CONSTR_CHECK:
- cxt->ckconstraints = lappend(cxt->ckconstraints, constraint);
- break;
-
- case CONSTR_NULL:
- case CONSTR_NOTNULL:
- case CONSTR_DEFAULT:
- case CONSTR_ATTR_DEFERRABLE:
- case CONSTR_ATTR_NOT_DEFERRABLE:
- case CONSTR_ATTR_DEFERRED:
- case CONSTR_ATTR_IMMEDIATE:
- elog(ERROR, "parser: illegal context for constraint (internal error)");
- break;
-
- default:
- elog(ERROR, "parser: unrecognized constraint (internal error)");
- break;
- }
-}
-
-static void
-transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
-{
- List *listptr;
- List *keys;
- IndexStmt *index;
- IndexElem *iparam;
- ColumnDef *column;
- List *columns;
- List *indexlist = NIL;
-
- /*
- * Run through the constraints that need to generate an index. For
- * PRIMARY KEY, mark each column as NOT NULL and create an index. For
- * UNIQUE, create an index as for PRIMARY KEY, but do not insist on
- * NOT NULL.
- */
- foreach(listptr, cxt->ixconstraints)
- {
- Constraint *constraint = lfirst(listptr);
-
- Assert(IsA(constraint, Constraint));
- Assert((constraint->contype == CONSTR_PRIMARY)
- || (constraint->contype == CONSTR_UNIQUE));
-
- index = makeNode(IndexStmt);
-
- index->unique = true;
- index->primary = (constraint->contype == CONSTR_PRIMARY);
- if (index->primary)
- {
- /* In ALTER TABLE case, a primary index might already exist */
- if (cxt->pkey != NULL ||
- (OidIsValid(cxt->relOid) &&
- relationHasPrimaryKey(cxt->relOid)))
- elog(ERROR, "%s / PRIMARY KEY multiple primary keys"
- " for table '%s' are not allowed",
- cxt->stmtType, (cxt->relation)->relname);
- cxt->pkey = index;
- }
-
- if (constraint->name != NULL)
- index->idxname = pstrdup(constraint->name);
- else if (constraint->contype == CONSTR_PRIMARY)
- index->idxname = makeObjectName((cxt->relation)->relname, NULL, "pkey");
- else
- index->idxname = NULL; /* will set it later */
-
- index->relation = cxt->relation;
- index->accessMethod = DEFAULT_INDEX_TYPE;
- index->indexParams = NIL;
- index->whereClause = NULL;
-
- /*
- * Make sure referenced keys exist. If we are making a PRIMARY
- * KEY index, also make sure they are NOT NULL.
- */
- foreach(keys, constraint->keys)
- {
- Ident *key = (Ident *) lfirst(keys);
- bool found = false;
-
- Assert(IsA(key, Ident));
- column = NULL;
- foreach(columns, cxt->columns)
- {
- column = lfirst(columns);
- Assert(IsA(column, ColumnDef));
- if (strcmp(column->colname, key->name) == 0)
- {
- found = true;
- break;
- }
- }
- if (found)
- {
- /* found column in the new table; force it to be NOT NULL */
- if (constraint->contype == CONSTR_PRIMARY)
- column->is_not_null = TRUE;
- }
- else if (SystemAttributeByName(key->name, cxt->hasoids) != NULL)
- {
- /*
- * column will be a system column in the new table, so
- * accept it. System columns can't ever be null, so no
- * need to worry about PRIMARY/NOT NULL constraint.
- */
- found = true;
- }
- else if (cxt->inhRelations)
- {
- /* try inherited tables */
- List *inher;
-
- foreach(inher, cxt->inhRelations)
- {
- RangeVar *inh = lfirst(inher);
- Relation rel;
- int count;
-
- Assert(IsA(inh, RangeVar));
- rel = heap_openrv(inh, AccessShareLock);
- if (rel->rd_rel->relkind != RELKIND_RELATION)
- elog(ERROR, "inherited table \"%s\" is not a relation",
- inh->relname);
- for (count = 0; count < rel->rd_att->natts; count++)
- {
- Form_pg_attribute inhattr = rel->rd_att->attrs[count];
- char *inhname = NameStr(inhattr->attname);
-
- if (strcmp(key->name, inhname) == 0)
- {
- found = true;
-
- /*
- * If the column is inherited, we currently
- * have no easy way to force it to be NOT
- * NULL. Only way I can see to fix this would
- * be to convert the inherited-column info to
- * ColumnDef nodes before we reach this point,
- * and then create the table from those nodes
- * rather than referencing the parent tables
- * later. That would likely be cleaner, but
- * too much work to contemplate right now.
- * Instead, raise an error if the inherited
- * column won't be NOT NULL. (Would a WARNING
- * be more reasonable?)
- */
- if (constraint->contype == CONSTR_PRIMARY &&
- !inhattr->attnotnull)
- elog(ERROR, "inherited attribute \"%s\" cannot be a PRIMARY KEY because it is not marked NOT NULL",
- inhname);
- break;
- }
- }
- heap_close(rel, NoLock);
- if (found)
- break;
- }
- }
- else if (OidIsValid(cxt->relOid))
- {
- /* ALTER TABLE case: does column already exist? */
- HeapTuple atttuple;
-
- atttuple = SearchSysCache(ATTNAME,
- ObjectIdGetDatum(cxt->relOid),
- PointerGetDatum(key->name),
- 0, 0);
- if (HeapTupleIsValid(atttuple))
- {
- found = true;
-
- /*
- * We require pre-existing column to be already marked
- * NOT NULL.
- */
- if (constraint->contype == CONSTR_PRIMARY &&
- !((Form_pg_attribute) GETSTRUCT(atttuple))->attnotnull)
- elog(ERROR, "Existing attribute \"%s\" cannot be a PRIMARY KEY because it is not marked NOT NULL",
- key->name);
- ReleaseSysCache(atttuple);
- }
- }
-
- if (!found)
- elog(ERROR, "%s: column \"%s\" named in key does not exist",
- cxt->stmtType, key->name);
-
- /* Check for PRIMARY KEY(foo, foo) */
- foreach(columns, index->indexParams)
- {
- iparam = (IndexElem *) lfirst(columns);
- if (iparam->name && strcmp(key->name, iparam->name) == 0)
- elog(ERROR, "%s: column \"%s\" appears twice in %s constraint",
- cxt->stmtType, key->name,
- index->primary ? "PRIMARY KEY" : "UNIQUE");
- }
-
- /* OK, add it to the index definition */
- iparam = makeNode(IndexElem);
- iparam->name = pstrdup(key->name);
- iparam->funcname = NIL;
- iparam->args = NIL;
- iparam->opclass = NIL;
- index->indexParams = lappend(index->indexParams, iparam);
- }
-
- indexlist = lappend(indexlist, index);
- }
-
- /*
- * Scan the index list and remove any redundant index specifications.
- * This can happen if, for instance, the user writes SERIAL PRIMARY
- * KEY or SERIAL UNIQUE. A strict reading of SQL92 would suggest
- * raising an error instead, but that strikes me as too
- * anal-retentive. - tgl 2001-02-14
- *
- * XXX in ALTER TABLE case, it'd be nice to look for duplicate
- * pre-existing indexes, too.
- */
- cxt->alist = NIL;
- if (cxt->pkey != NULL)
- {
- /* Make sure we keep the PKEY index in preference to others... */
- cxt->alist = makeList1(cxt->pkey);
- }
- while (indexlist != NIL)
- {
- index = lfirst(indexlist);
-
- /* if it's pkey, it's already in cxt->alist */
- if (index != cxt->pkey)
- {
- bool keep = true;
- List *priorlist;
-
- foreach(priorlist, cxt->alist)
- {
- IndexStmt *priorindex = lfirst(priorlist);
-
- if (equal(index->indexParams, priorindex->indexParams))
- {
- /*
- * If the prior index is as yet unnamed, and this one
- * is named, then transfer the name to the prior
- * index. This ensures that if we have named and
- * unnamed constraints, we'll use (at least one of)
- * the names for the index.
- */
- if (priorindex->idxname == NULL)
- priorindex->idxname = index->idxname;
- keep = false;
- break;
- }
- }
-
- if (keep)
- cxt->alist = lappend(cxt->alist, index);
- }
-
- indexlist = lnext(indexlist);
- }
-
- /*
- * Finally, select unique names for all not-previously-named indices,
- * and display WARNING messages.
- *
- * XXX in ALTER TABLE case, we fail to consider name collisions against
- * pre-existing indexes.
- */
- foreach(indexlist, cxt->alist)
- {
- index = lfirst(indexlist);
-
- if (index->idxname == NULL && index->indexParams != NIL)
- {
- iparam = lfirst(index->indexParams);
- index->idxname = CreateIndexName(cxt->relation->relname,
- iparam->name ? iparam->name :
- strVal(llast(iparam->funcname)),
- "key", cxt->alist);
- }
- if (index->idxname == NULL) /* should not happen */
- elog(ERROR, "%s: failed to make implicit index name",
- cxt->stmtType);
-
- elog(NOTICE, "%s / %s%s will create implicit index '%s' for table '%s'",
- cxt->stmtType,
- (strcmp(cxt->stmtType, "ALTER TABLE") == 0) ? "ADD " : "",
- (index->primary ? "PRIMARY KEY" : "UNIQUE"),
- index->idxname, cxt->relation->relname);
- }
-}
-
-static void
-transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
-{
- CreateTrigStmt *fk_trigger;
- List *fkactions = NIL;
- List *fkclist;
- List *fk_attr;
- List *pk_attr;
- Ident *id;
- Oid pktypoid[INDEX_MAX_KEYS];
- Oid fktypoid[INDEX_MAX_KEYS];
- int i;
-
- if (cxt->fkconstraints == NIL)
- return;
-
- elog(NOTICE, "%s will create implicit trigger(s) for FOREIGN KEY check(s)",
- cxt->stmtType);
-
- foreach(fkclist, cxt->fkconstraints)
- {
- FkConstraint *fkconstraint = (FkConstraint *) lfirst(fkclist);
- int attnum;
- List *fkattrs;
-
- /*
- * If the constraint has no name, set it to <unnamed>
- */
- if (fkconstraint->constr_name == NULL)
- fkconstraint->constr_name = "<unnamed>";
-
- for (attnum = 0; attnum < INDEX_MAX_KEYS; attnum++)
- pktypoid[attnum] = fktypoid[attnum] = InvalidOid;
-
- /*
- * Look up the referencing attributes to make sure they exist (or
- * will exist) in this table, and remember their type OIDs.
- */
- attnum = 0;
- foreach(fkattrs, fkconstraint->fk_attrs)
- {
- Ident *fkattr = lfirst(fkattrs);
-
- if (attnum >= INDEX_MAX_KEYS)
- elog(ERROR, "Can only have %d keys in a foreign key",
- INDEX_MAX_KEYS);
- fktypoid[attnum++] = transformFkeyGetColType(cxt,
- fkattr->name);
- }
-
- /*
- * If the attribute list for the referenced table was omitted,
- * lookup the definition of the primary key.
- */
- if (fkconstraint->pk_attrs == NIL)
- {
- if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0)
- transformFkeyGetPrimaryKey(fkconstraint, pktypoid);
- else if (cxt->pkey != NULL)
- {
- /* Use the to-be-created primary key */
- List *attr;
-
- attnum = 0;
- foreach(attr, cxt->pkey->indexParams)
- {
- IndexElem *ielem = lfirst(attr);
- Ident *pkattr = (Ident *) makeNode(Ident);
-
- Assert(ielem->name); /* no func index here */
- pkattr->name = pstrdup(ielem->name);
- fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs,
- pkattr);
- if (attnum >= INDEX_MAX_KEYS)
- elog(ERROR, "Can only have %d keys in a foreign key",
- INDEX_MAX_KEYS);
- pktypoid[attnum++] = transformFkeyGetColType(cxt,
- ielem->name);
- }
- }
- else
- {
- /* In ALTER TABLE case, primary key may already exist */
- if (OidIsValid(cxt->relOid))
- transformFkeyGetPrimaryKey(fkconstraint, pktypoid);
- else
- elog(ERROR, "PRIMARY KEY for referenced table \"%s\" not found",
- fkconstraint->pktable->relname);
- }
- }
- else
- {
- /* Validate the specified referenced key list */
- if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0)
- transformFkeyCheckAttrs(fkconstraint, pktypoid);
- else
- {
- /* Look for a matching new unique/primary constraint */
- List *index;
- bool found = false;
-
- foreach(index, cxt->alist)
- {
- IndexStmt *ind = lfirst(index);
- List *pkattrs;
-
- if (!ind->unique)
- continue;
- if (length(ind->indexParams) !=
- length(fkconstraint->pk_attrs))
- continue;
- attnum = 0;
- foreach(pkattrs, fkconstraint->pk_attrs)
- {
- Ident *pkattr = lfirst(pkattrs);
- List *indparms;
-
- found = false;
- foreach(indparms, ind->indexParams)
- {
- IndexElem *indparm = lfirst(indparms);
-
- if (indparm->name &&
- strcmp(indparm->name, pkattr->name) == 0)
- {
- found = true;
- break;
- }
- }
- if (!found)
- break;
- if (attnum >= INDEX_MAX_KEYS)
- elog(ERROR, "Can only have %d keys in a foreign key",
- INDEX_MAX_KEYS);
- pktypoid[attnum++] = transformFkeyGetColType(cxt,
- pkattr->name);
- }
- if (found)
- break;
- }
- if (!found)
- {
- /*
- * In ALTER TABLE case, such an index may already
- * exist
- */
- if (OidIsValid(cxt->relOid))
- transformFkeyCheckAttrs(fkconstraint, pktypoid);
- else
- elog(ERROR, "UNIQUE constraint matching given keys for referenced table \"%s\" not found",
- fkconstraint->pktable->relname);
- }
- }
- }
-
- /* Be sure referencing and referenced column types are comparable */
- for (i = 0; i < INDEX_MAX_KEYS && fktypoid[i] != 0; i++)
- {
- /*
- * fktypoid[i] is the foreign key table's i'th element's type
- * pktypoid[i] is the primary key table's i'th element's type
- *
- * We let oper() do our work for us, including elog(ERROR) if
- * the types don't compare with =
- */
- Operator o = oper(makeList1(makeString("=")),
- fktypoid[i], pktypoid[i], false);
-
- ReleaseSysCache(o);
- }
-
- /*
- * Build a CREATE CONSTRAINT TRIGGER statement for the CHECK
- * action.
- */
- fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relation = cxt->relation;
- fk_trigger->funcname = SystemFuncName("RI_FKey_check_ins");
- fk_trigger->before = false;
- fk_trigger->row = true;
- fk_trigger->actions[0] = 'i';
- fk_trigger->actions[1] = 'u';
- fk_trigger->actions[2] = '\0';
- fk_trigger->lang = NULL;
- fk_trigger->text = NULL;
-
- fk_trigger->attr = NIL;
- fk_trigger->when = NULL;
- fk_trigger->isconstraint = true;
- fk_trigger->deferrable = fkconstraint->deferrable;
- fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrel = fkconstraint->pktable;
-
- fk_trigger->args = NIL;
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->constr_name));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString((cxt->relation)->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->match_type));
- fk_attr = fkconstraint->fk_attrs;
- pk_attr = fkconstraint->pk_attrs;
- if (length(fk_attr) != length(pk_attr))
- elog(ERROR, "number of key attributes in referenced table must be equal to foreign key"
- "\n\tIllegal FOREIGN KEY definition references \"%s\"",
- fkconstraint->pktable->relname);
-
- while (fk_attr != NIL)
- {
- id = (Ident *) lfirst(fk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- id = (Ident *) lfirst(pk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- fk_attr = lnext(fk_attr);
- pk_attr = lnext(pk_attr);
- }
-
- fkactions = lappend(fkactions, (Node *) fk_trigger);
-
- /*
- * Build a CREATE CONSTRAINT TRIGGER statement for the ON DELETE
- * action fired on the PK table !!!
- */
- fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relation = fkconstraint->pktable;
- fk_trigger->before = false;
- fk_trigger->row = true;
- fk_trigger->actions[0] = 'd';
- fk_trigger->actions[1] = '\0';
- fk_trigger->lang = NULL;
- fk_trigger->text = NULL;
-
- fk_trigger->attr = NIL;
- fk_trigger->when = NULL;
- fk_trigger->isconstraint = true;
- fk_trigger->deferrable = fkconstraint->deferrable;
- fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrel = cxt->relation;
- switch ((fkconstraint->actions & FKCONSTR_ON_DELETE_MASK)
- >> FKCONSTR_ON_DELETE_SHIFT)
- {
- case FKCONSTR_ON_KEY_NOACTION:
- fk_trigger->funcname = SystemFuncName("RI_FKey_noaction_del");
- break;
- case FKCONSTR_ON_KEY_RESTRICT:
- fk_trigger->deferrable = false;
- fk_trigger->initdeferred = false;
- fk_trigger->funcname = SystemFuncName("RI_FKey_restrict_del");
- break;
- case FKCONSTR_ON_KEY_CASCADE:
- fk_trigger->funcname = SystemFuncName("RI_FKey_cascade_del");
- break;
- case FKCONSTR_ON_KEY_SETNULL:
- fk_trigger->funcname = SystemFuncName("RI_FKey_setnull_del");
- break;
- case FKCONSTR_ON_KEY_SETDEFAULT:
- fk_trigger->funcname = SystemFuncName("RI_FKey_setdefault_del");
- break;
- default:
- elog(ERROR, "Only one ON DELETE action can be specified for FOREIGN KEY constraint");
- break;
- }
-
- fk_trigger->args = NIL;
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->constr_name));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString((cxt->relation)->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->match_type));
- fk_attr = fkconstraint->fk_attrs;
- pk_attr = fkconstraint->pk_attrs;
- while (fk_attr != NIL)
- {
- id = (Ident *) lfirst(fk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- id = (Ident *) lfirst(pk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- fk_attr = lnext(fk_attr);
- pk_attr = lnext(pk_attr);
- }
-
- fkactions = lappend(fkactions, (Node *) fk_trigger);
-
- /*
- * Build a CREATE CONSTRAINT TRIGGER statement for the ON UPDATE
- * action fired on the PK table !!!
- */
- fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relation = fkconstraint->pktable;
- fk_trigger->before = false;
- fk_trigger->row = true;
- fk_trigger->actions[0] = 'u';
- fk_trigger->actions[1] = '\0';
- fk_trigger->lang = NULL;
- fk_trigger->text = NULL;
-
- fk_trigger->attr = NIL;
- fk_trigger->when = NULL;
- fk_trigger->isconstraint = true;
- fk_trigger->deferrable = fkconstraint->deferrable;
- fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrel = cxt->relation;
- switch ((fkconstraint->actions & FKCONSTR_ON_UPDATE_MASK)
- >> FKCONSTR_ON_UPDATE_SHIFT)
- {
- case FKCONSTR_ON_KEY_NOACTION:
- fk_trigger->funcname = SystemFuncName("RI_FKey_noaction_upd");
- break;
- case FKCONSTR_ON_KEY_RESTRICT:
- fk_trigger->deferrable = false;
- fk_trigger->initdeferred = false;
- fk_trigger->funcname = SystemFuncName("RI_FKey_restrict_upd");
- break;
- case FKCONSTR_ON_KEY_CASCADE:
- fk_trigger->funcname = SystemFuncName("RI_FKey_cascade_upd");
- break;
- case FKCONSTR_ON_KEY_SETNULL:
- fk_trigger->funcname = SystemFuncName("RI_FKey_setnull_upd");
- break;
- case FKCONSTR_ON_KEY_SETDEFAULT:
- fk_trigger->funcname = SystemFuncName("RI_FKey_setdefault_upd");
- break;
- default:
- elog(ERROR, "Only one ON UPDATE action can be specified for FOREIGN KEY constraint");
- break;
- }
-
- fk_trigger->args = NIL;
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->constr_name));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString((cxt->relation)->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable->relname));
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->match_type));
- fk_attr = fkconstraint->fk_attrs;
- pk_attr = fkconstraint->pk_attrs;
- while (fk_attr != NIL)
- {
- id = (Ident *) lfirst(fk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- id = (Ident *) lfirst(pk_attr);
- fk_trigger->args = lappend(fk_trigger->args,
- makeString(id->name));
-
- fk_attr = lnext(fk_attr);
- pk_attr = lnext(pk_attr);
- }
-
- fkactions = lappend(fkactions, (Node *) fk_trigger);
- }
-
- /*
- * Attach completed list of extra actions to cxt->alist. We cannot do
- * this earlier, because we assume above that cxt->alist still holds
- * only IndexStmts.
- */
- cxt->alist = nconc(cxt->alist, fkactions);
-}
-
-/*
- * transformIndexStmt -
- * transforms the qualification of the index statement
- */
-static Query *
-transformIndexStmt(ParseState *pstate, IndexStmt *stmt)
-{
- Query *qry;
- RangeTblEntry *rte;
-
- qry = makeNode(Query);
- qry->commandType = CMD_UTILITY;
-
- /* take care of the where clause */
- if (stmt->whereClause)
- {
- /*
- * Put the parent table into the rtable so that the WHERE clause
- * can refer to its fields without qualification. Note that this
- * only works if the parent table already exists --- so we can't
- * easily support predicates on indexes created implicitly by
- * CREATE TABLE. Fortunately, that's not necessary.
- */
- rte = addRangeTableEntry(pstate, stmt->relation, NULL, false, true);
-
- /* no to join list, yes to namespace */
- addRTEtoQuery(pstate, rte, false, true);
-
- stmt->whereClause = transformWhereClause(pstate, stmt->whereClause);
- }
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- stmt->rangetable = pstate->p_rtable;
-
- qry->utilityStmt = (Node *) stmt;
-
- return qry;
-}
-
-/*
- * transformRuleStmt -
- * transform a Create Rule Statement. The actions is a list of parse
- * trees which is transformed into a list of query trees.
- */
-static Query *
-transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
- List **extras_before, List **extras_after)
-{
- Query *qry;
- RangeTblEntry *oldrte;
- RangeTblEntry *newrte;
-
- qry = makeNode(Query);
- qry->commandType = CMD_UTILITY;
- qry->utilityStmt = (Node *) stmt;
-
- /*
- * To avoid deadlock, make sure the first thing we do is grab
- * AccessExclusiveLock on the target relation. This will be needed by
- * DefineQueryRewrite(), and we don't want to grab a lesser lock
- * beforehand. We don't need to hold a refcount on the relcache
- * entry, however.
- */
- heap_close(heap_openrv(stmt->relation, AccessExclusiveLock),
- NoLock);
-
- /*
- * NOTE: 'OLD' must always have a varno equal to 1 and 'NEW' equal to
- * 2. Set up their RTEs in the main pstate for use in parsing the
- * rule qualification.
- */
- Assert(pstate->p_rtable == NIL);
- oldrte = addRangeTableEntry(pstate, stmt->relation,
- makeAlias("*OLD*", NIL),
- false, true);
- newrte = addRangeTableEntry(pstate, stmt->relation,
- makeAlias("*NEW*", NIL),
- false, true);
- /* Must override addRangeTableEntry's default access-check flags */
- oldrte->checkForRead = false;
- newrte->checkForRead = false;
-
- /*
- * They must be in the namespace too for lookup purposes, but only add
- * the one(s) that are relevant for the current kind of rule. In an
- * UPDATE rule, quals must refer to OLD.field or NEW.field to be
- * unambiguous, but there's no need to be so picky for INSERT &
- * DELETE. (Note we marked the RTEs "inFromCl = true" above to allow
- * unqualified references to their fields.) We do not add them to the
- * joinlist.
- */
- switch (stmt->event)
- {
- case CMD_SELECT:
- addRTEtoQuery(pstate, oldrte, false, true);
- break;
- case CMD_UPDATE:
- addRTEtoQuery(pstate, oldrte, false, true);
- addRTEtoQuery(pstate, newrte, false, true);
- break;
- case CMD_INSERT:
- addRTEtoQuery(pstate, newrte, false, true);
- break;
- case CMD_DELETE:
- addRTEtoQuery(pstate, oldrte, false, true);
- break;
- default:
- elog(ERROR, "transformRuleStmt: unexpected event type %d",
- (int) stmt->event);
- break;
- }
-
- /* take care of the where clause */
- stmt->whereClause = transformWhereClause(pstate, stmt->whereClause);
-
- if (length(pstate->p_rtable) != 2) /* naughty, naughty... */
- elog(ERROR, "Rule WHERE condition may not contain references to other relations");
-
- /* save info about sublinks in where clause */
- qry->hasSubLinks = pstate->p_hasSubLinks;
-
- /*
- * 'instead nothing' rules with a qualification need a query
- * rangetable so the rewrite handler can add the negated rule
- * qualification to the original query. We create a query with the new
- * command type CMD_NOTHING here that is treated specially by the
- * rewrite system.
- */
- if (stmt->actions == NIL)
- {
- Query *nothing_qry = makeNode(Query);
-
- nothing_qry->commandType = CMD_NOTHING;
- nothing_qry->rtable = pstate->p_rtable;
- nothing_qry->jointree = makeFromExpr(NIL, NULL); /* no join wanted */
-
- stmt->actions = makeList1(nothing_qry);
- }
- else
- {
- List *oldactions;
- List *newactions = NIL;
-
- /*
- * transform each statement, like parse_analyze()
- */
- foreach(oldactions, stmt->actions)
- {
- Node *action = (Node *) lfirst(oldactions);
- ParseState *sub_pstate = make_parsestate(pstate->parentParseState);
- Query *sub_qry,
- *top_subqry;
- bool has_old,
- has_new;
-
- /*
- * Set up OLD/NEW in the rtable for this statement. The
- * entries are marked not inFromCl because we don't want them
- * to be referred to by unqualified field names nor "*" in the
- * rule actions. We must add them to the namespace, however,
- * or they won't be accessible at all. We decide later
- * whether to put them in the joinlist.
- */
- oldrte = addRangeTableEntry(sub_pstate, stmt->relation,
- makeAlias("*OLD*", NIL),
- false, false);
- newrte = addRangeTableEntry(sub_pstate, stmt->relation,
- makeAlias("*NEW*", NIL),
- false, false);
- oldrte->checkForRead = false;
- newrte->checkForRead = false;
- addRTEtoQuery(sub_pstate, oldrte, false, true);
- addRTEtoQuery(sub_pstate, newrte, false, true);
-
- /* Transform the rule action statement */
- top_subqry = transformStmt(sub_pstate, action,
- extras_before, extras_after);
-
- /*
- * We cannot support utility-statement actions (eg NOTIFY)
- * with nonempty rule WHERE conditions, because there's no way
- * to make the utility action execute conditionally.
- */
- if (top_subqry->commandType == CMD_UTILITY &&
- stmt->whereClause != NULL)
- elog(ERROR, "Rules with WHERE conditions may only have SELECT, INSERT, UPDATE, or DELETE actions");
-
- /*
- * If the action is INSERT...SELECT, OLD/NEW have been pushed
- * down into the SELECT, and that's what we need to look at.
- * (Ugly kluge ... try to fix this when we redesign
- * querytrees.)
- */
- sub_qry = getInsertSelectQuery(top_subqry, NULL);
-
- /*
- * Validate action's use of OLD/NEW, qual too
- */
- has_old =
- rangeTableEntry_used((Node *) sub_qry, PRS2_OLD_VARNO, 0) ||
- rangeTableEntry_used(stmt->whereClause, PRS2_OLD_VARNO, 0);
- has_new =
- rangeTableEntry_used((Node *) sub_qry, PRS2_NEW_VARNO, 0) ||
- rangeTableEntry_used(stmt->whereClause, PRS2_NEW_VARNO, 0);
-
- switch (stmt->event)
- {
- case CMD_SELECT:
- if (has_old)
- elog(ERROR, "ON SELECT rule may not use OLD");
- if (has_new)
- elog(ERROR, "ON SELECT rule may not use NEW");
- break;
- case CMD_UPDATE:
- /* both are OK */
- break;
- case CMD_INSERT:
- if (has_old)
- elog(ERROR, "ON INSERT rule may not use OLD");
- break;
- case CMD_DELETE:
- if (has_new)
- elog(ERROR, "ON DELETE rule may not use NEW");
- break;
- default:
- elog(ERROR, "transformRuleStmt: unexpected event type %d",
- (int) stmt->event);
- break;
- }
-
- /*
- * For efficiency's sake, add OLD to the rule action's
- * jointree only if it was actually referenced in the
- * statement or qual.
- *
- * For INSERT, NEW is not really a relation (only a reference to
- * the to-be-inserted tuple) and should never be added to the
- * jointree.
- *
- * For UPDATE, we treat NEW as being another kind of reference to
- * OLD, because it represents references to *transformed*
- * tuples of the existing relation. It would be wrong to
- * enter NEW separately in the jointree, since that would
- * cause a double join of the updated relation. It's also
- * wrong to fail to make a jointree entry if only NEW and not
- * OLD is mentioned.
- */
- if (has_old || (has_new && stmt->event == CMD_UPDATE))
- {
- /* hack so we can use addRTEtoQuery() */
- sub_pstate->p_rtable = sub_qry->rtable;
- sub_pstate->p_joinlist = sub_qry->jointree->fromlist;
- addRTEtoQuery(sub_pstate, oldrte, true, false);
- sub_qry->jointree->fromlist = sub_pstate->p_joinlist;
- }
-
- newactions = lappend(newactions, top_subqry);
-
- release_pstate_resources(sub_pstate);
- pfree(sub_pstate);
- }
-
- stmt->actions = newactions;
- }
-
- return qry;
-}
-
-
-/*
- * transformSelectStmt -
- * transforms a Select Statement
- *
- * Note: this is also used for DECLARE CURSOR statements.
- */
-static Query *
-transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
-{
- Query *qry = makeNode(Query);
- Node *qual;
-
- qry->commandType = CMD_SELECT;
-
- if (stmt->portalname)
- {
- /* DECLARE CURSOR */
- if (stmt->into)
- elog(ERROR, "DECLARE CURSOR must not specify INTO");
- if (stmt->forUpdate)
- elog(ERROR, "DECLARE/UPDATE is not supported"
- "\n\tCursors must be READ ONLY");
-
- /*
- * 15 august 1991 -- since 3.0 postgres does locking right, we
- * discovered that portals were violating locking protocol. portal
- * locks cannot span xacts. as a short-term fix, we installed the
- * check here. -- mao
- */
- if (!IsTransactionBlock())
- elog(ERROR, "DECLARE CURSOR may only be used in begin/end transaction blocks");
-
- qry->into = makeNode(RangeVar);
- qry->into->relname = stmt->portalname;
- qry->isPortal = TRUE;
- qry->isBinary = stmt->binary; /* internal portal */
- }
- else
- {
- /* SELECT */
- qry->into = stmt->into;
- qry->isPortal = FALSE;
- qry->isBinary = FALSE;
- }
-
- /* make FOR UPDATE clause available to addRangeTableEntry */
- pstate->p_forUpdate = stmt->forUpdate;
-
- /* process the FROM clause */
- transformFromClause(pstate, stmt->fromClause);
-
- /* transform targetlist */
- qry->targetList = transformTargetList(pstate, stmt->targetList);
-
- if (stmt->intoColNames)
- applyColumnNames(qry->targetList, stmt->intoColNames);
-
- /* transform WHERE */
- qual = transformWhereClause(pstate, stmt->whereClause);
-
- /*
- * Initial processing of HAVING clause is just like WHERE clause.
- * Additional work will be done in optimizer/plan/planner.c.
- */
- qry->havingQual = transformWhereClause(pstate, stmt->havingClause);
-
- qry->groupClause = transformGroupClause(pstate,
- stmt->groupClause,
- qry->targetList);
-
- qry->sortClause = transformSortClause(pstate,
- stmt->sortClause,
- qry->targetList);
-
- qry->distinctClause = transformDistinctClause(pstate,
- stmt->distinctClause,
- qry->targetList,
- &qry->sortClause);
-
- qry->limitOffset = stmt->limitOffset;
- qry->limitCount = stmt->limitCount;
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- qry->hasAggs = pstate->p_hasAggs;
- if (pstate->p_hasAggs || qry->groupClause || qry->havingQual)
- parseCheckAggregates(pstate, qry, qual);
-
- qry->rtable = pstate->p_rtable;
- qry->jointree = makeFromExpr(pstate->p_joinlist, qual);
-
- if (stmt->forUpdate != NIL)
- transformForUpdate(qry, stmt->forUpdate);
-
- return qry;
-}
-
-/*
- * transformSetOperationsStmt -
- * transforms a set-operations tree
- *
- * A set-operation tree is just a SELECT, but with UNION/INTERSECT/EXCEPT
- * structure to it. We must transform each leaf SELECT and build up a top-
- * level Query that contains the leaf SELECTs as subqueries in its rangetable.
- * The tree of set operations is converted into the setOperations field of
- * the top-level Query.
- */
-static Query *
-transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
-{
- Query *qry = makeNode(Query);
- SelectStmt *leftmostSelect;
- int leftmostRTI;
- Query *leftmostQuery;
- SetOperationStmt *sostmt;
- RangeVar *into;
- List *intoColNames;
- char *portalname;
- bool binary;
- List *sortClause;
- Node *limitOffset;
- Node *limitCount;
- List *forUpdate;
- Node *node;
- List *lefttl,
- *dtlist,
- *targetvars,
- *targetnames,
- *sv_namespace,
- *sv_rtable;
- RangeTblEntry *jrte;
- RangeTblRef *jrtr;
- int tllen;
-
- qry->commandType = CMD_SELECT;
-
- /*
- * Find leftmost leaf SelectStmt; extract the one-time-only items from
- * it and from the top-level node.
- */
- leftmostSelect = stmt->larg;
- while (leftmostSelect && leftmostSelect->op != SETOP_NONE)
- leftmostSelect = leftmostSelect->larg;
- Assert(leftmostSelect && IsA(leftmostSelect, SelectStmt) &&
- leftmostSelect->larg == NULL);
- into = leftmostSelect->into;
- intoColNames = leftmostSelect->intoColNames;
- portalname = stmt->portalname;
- binary = stmt->binary;
-
- /* clear them to prevent complaints in transformSetOperationTree() */
- leftmostSelect->into = NULL;
- leftmostSelect->intoColNames = NIL;
- stmt->portalname = NULL;
- stmt->binary = false;
-
- /*
- * These are not one-time, exactly, but we want to process them here
- * and not let transformSetOperationTree() see them --- else it'll
- * just recurse right back here!
- */
- sortClause = stmt->sortClause;
- limitOffset = stmt->limitOffset;
- limitCount = stmt->limitCount;
- forUpdate = stmt->forUpdate;
-
- stmt->sortClause = NIL;
- stmt->limitOffset = NULL;
- stmt->limitCount = NULL;
- stmt->forUpdate = NIL;
-
- /* We don't support forUpdate with set ops at the moment. */
- if (forUpdate)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
-
- /*
- * Recursively transform the components of the tree.
- */
- sostmt = (SetOperationStmt *) transformSetOperationTree(pstate, stmt);
- Assert(sostmt && IsA(sostmt, SetOperationStmt));
- qry->setOperations = (Node *) sostmt;
-
- /*
- * Re-find leftmost SELECT (now it's a sub-query in rangetable)
- */
- node = sostmt->larg;
- while (node && IsA(node, SetOperationStmt))
- node = ((SetOperationStmt *) node)->larg;
- Assert(node && IsA(node, RangeTblRef));
- leftmostRTI = ((RangeTblRef *) node)->rtindex;
- leftmostQuery = rt_fetch(leftmostRTI, pstate->p_rtable)->subquery;
- Assert(leftmostQuery != NULL);
-
- /*
- * Generate dummy targetlist for outer query using column names of
- * leftmost select and common datatypes of topmost set operation. Also
- * make lists of the dummy vars and their names for use in parsing
- * ORDER BY.
- */
- qry->targetList = NIL;
- targetvars = NIL;
- targetnames = NIL;
- lefttl = leftmostQuery->targetList;
- foreach(dtlist, sostmt->colTypes)
- {
- Oid colType = (Oid) lfirsti(dtlist);
- Resdom *leftResdom = ((TargetEntry *) lfirst(lefttl))->resdom;
- char *colName = pstrdup(leftResdom->resname);
- Resdom *resdom;
- Node *expr;
-
- resdom = makeResdom((AttrNumber) pstate->p_last_resno++,
- colType,
- -1,
- colName,
- false);
- expr = (Node *) makeVar(1,
- leftResdom->resno,
- colType,
- -1,
- 0);
- qry->targetList = lappend(qry->targetList,
- makeTargetEntry(resdom, expr));
- targetvars = lappend(targetvars, expr);
- targetnames = lappend(targetnames, makeString(colName));
- lefttl = lnext(lefttl);
- }
-
- /*
- * Insert one-time items into top-level query
- *
- * This needs to agree with transformSelectStmt!
- */
- if (portalname)
- {
- /* DECLARE CURSOR */
- if (into)
- elog(ERROR, "DECLARE CURSOR must not specify INTO");
- if (forUpdate)
- elog(ERROR, "DECLARE/UPDATE is not supported"
- "\n\tCursors must be READ ONLY");
-
- /*
- * 15 august 1991 -- since 3.0 postgres does locking right, we
- * discovered that portals were violating locking protocol. portal
- * locks cannot span xacts. as a short-term fix, we installed the
- * check here. -- mao
- */
- if (!IsTransactionBlock())
- elog(ERROR, "DECLARE CURSOR may only be used in begin/end transaction blocks");
-
- qry->into = makeNode(RangeVar);
- qry->into->relname = portalname;
- qry->isPortal = TRUE;
- qry->isBinary = binary; /* internal portal */
- }
- else
- {
- /* SELECT */
- qry->into = into;
- qry->isPortal = FALSE;
- qry->isBinary = FALSE;
- }
-
- /*
- * Any column names from CREATE TABLE AS need to be attached to both the
- * top level and the leftmost subquery. We do not do this earlier
- * because we do *not* want the targetnames list to be affected.
- */
- if (intoColNames)
- {
- applyColumnNames(qry->targetList, intoColNames);
- applyColumnNames(leftmostQuery->targetList, intoColNames);
- }
-
- /*
- * As a first step towards supporting sort clauses that are
- * expressions using the output columns, generate a namespace entry
- * that makes the output columns visible. A Join RTE node is handy
- * for this, since we can easily control the Vars generated upon
- * matches.
- *
- * Note: we don't yet do anything useful with such cases, but at least
- * "ORDER BY upper(foo)" will draw the right error message rather than
- * "foo not found".
- */
- jrte = addRangeTableEntryForJoin(NULL,
- targetnames,
- JOIN_INNER,
- targetvars,
- NULL,
- true);
- jrtr = makeNode(RangeTblRef);
- jrtr->rtindex = 1;
-
- sv_rtable = pstate->p_rtable;
- pstate->p_rtable = makeList1(jrte);
-
- sv_namespace = pstate->p_namespace;
- pstate->p_namespace = makeList1(jrtr);
-
- /*
- * For now, we don't support resjunk sort clauses on the output of a
- * setOperation tree --- you can only use the SQL92-spec options of
- * selecting an output column by name or number. Enforce by checking
- * that transformSortClause doesn't add any items to tlist.
- */
- tllen = length(qry->targetList);
-
- qry->sortClause = transformSortClause(pstate,
- sortClause,
- qry->targetList);
-
- pstate->p_namespace = sv_namespace;
- pstate->p_rtable = sv_rtable;
-
- if (tllen != length(qry->targetList))
- elog(ERROR, "ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns");
-
- qry->limitOffset = limitOffset;
- qry->limitCount = limitCount;
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- qry->hasAggs = pstate->p_hasAggs;
- if (pstate->p_hasAggs || qry->groupClause || qry->havingQual)
- parseCheckAggregates(pstate, qry, NULL);
-
- qry->rtable = pstate->p_rtable;
- qry->jointree = makeFromExpr(pstate->p_joinlist, NULL);
-
- if (forUpdate != NIL)
- transformForUpdate(qry, forUpdate);
-
- return qry;
-}
-
-/*
- * transformSetOperationTree
- * Recursively transform leaves and internal nodes of a set-op tree
- */
-static Node *
-transformSetOperationTree(ParseState *pstate, SelectStmt *stmt)
-{
- bool isLeaf;
-
- Assert(stmt && IsA(stmt, SelectStmt));
-
- /*
- * Validity-check both leaf and internal SELECTs for disallowed ops.
- */
- if (stmt->into)
- elog(ERROR, "INTO is only allowed on first SELECT of UNION/INTERSECT/EXCEPT");
- if (stmt->portalname) /* should not happen */
- elog(ERROR, "Portal may not appear in UNION/INTERSECT/EXCEPT");
- /* We don't support forUpdate with set ops at the moment. */
- if (stmt->forUpdate)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
-
- /*
- * If an internal node of a set-op tree has ORDER BY, UPDATE, or LIMIT
- * clauses attached, we need to treat it like a leaf node to generate
- * an independent sub-Query tree. Otherwise, it can be represented by
- * a SetOperationStmt node underneath the parent Query.
- */
- if (stmt->op == SETOP_NONE)
- {
- Assert(stmt->larg == NULL && stmt->rarg == NULL);
- isLeaf = true;
- }
- else
- {
- Assert(stmt->larg != NULL && stmt->rarg != NULL);
- if (stmt->sortClause || stmt->limitOffset || stmt->limitCount ||
- stmt->forUpdate)
- isLeaf = true;
- else
- isLeaf = false;
- }
-
- if (isLeaf)
- {
- /* Process leaf SELECT */
- List *selectList;
- Query *selectQuery;
- char selectName[32];
- RangeTblEntry *rte;
- RangeTblRef *rtr;
-
- /*
- * Transform SelectStmt into a Query.
- *
- * Note: previously transformed sub-queries don't affect the parsing
- * of this sub-query, because they are not in the toplevel
- * pstate's namespace list.
- */
- selectList = parse_analyze((Node *) stmt, pstate);
-
- Assert(length(selectList) == 1);
- selectQuery = (Query *) lfirst(selectList);
-
- /*
- * Make the leaf query be a subquery in the top-level rangetable.
- */
- sprintf(selectName, "*SELECT* %d", length(pstate->p_rtable) + 1);
- rte = addRangeTableEntryForSubquery(pstate,
- selectQuery,
- makeAlias(selectName, NIL),
- false);
-
- /*
- * Return a RangeTblRef to replace the SelectStmt in the set-op
- * tree.
- */
- rtr = makeNode(RangeTblRef);
- /* assume new rte is at end */
- rtr->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtr->rtindex, pstate->p_rtable));
- return (Node *) rtr;
- }
- else
- {
- /* Process an internal node (set operation node) */
- SetOperationStmt *op = makeNode(SetOperationStmt);
- List *lcoltypes;
- List *rcoltypes;
- const char *context;
-
- context = (stmt->op == SETOP_UNION ? "UNION" :
- (stmt->op == SETOP_INTERSECT ? "INTERSECT" :
- "EXCEPT"));
-
- op->op = stmt->op;
- op->all = stmt->all;
-
- /*
- * Recursively transform the child nodes.
- */
- op->larg = transformSetOperationTree(pstate, stmt->larg);
- op->rarg = transformSetOperationTree(pstate, stmt->rarg);
-
- /*
- * Verify that the two children have the same number of non-junk
- * columns, and determine the types of the merged output columns.
- */
- lcoltypes = getSetColTypes(pstate, op->larg);
- rcoltypes = getSetColTypes(pstate, op->rarg);
- if (length(lcoltypes) != length(rcoltypes))
- elog(ERROR, "Each %s query must have the same number of columns",
- context);
- op->colTypes = NIL;
- while (lcoltypes != NIL)
- {
- Oid lcoltype = (Oid) lfirsti(lcoltypes);
- Oid rcoltype = (Oid) lfirsti(rcoltypes);
- Oid rescoltype;
-
- rescoltype = select_common_type(makeListi2(lcoltype, rcoltype),
- context);
- op->colTypes = lappendi(op->colTypes, rescoltype);
- lcoltypes = lnext(lcoltypes);
- rcoltypes = lnext(rcoltypes);
- }
-
- return (Node *) op;
- }
-}
-
-/*
- * getSetColTypes
- * Get output column types of an (already transformed) set-op node
- */
-static List *
-getSetColTypes(ParseState *pstate, Node *node)
-{
- if (IsA(node, RangeTblRef))
- {
- RangeTblRef *rtr = (RangeTblRef *) node;
- RangeTblEntry *rte = rt_fetch(rtr->rtindex, pstate->p_rtable);
- Query *selectQuery = rte->subquery;
- List *result = NIL;
- List *tl;
-
- Assert(selectQuery != NULL);
- /* Get types of non-junk columns */
- foreach(tl, selectQuery->targetList)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Resdom *resnode = tle->resdom;
-
- if (resnode->resjunk)
- continue;
- result = lappendi(result, resnode->restype);
- }
- return result;
- }
- else if (IsA(node, SetOperationStmt))
- {
- SetOperationStmt *op = (SetOperationStmt *) node;
-
- /* Result already computed during transformation of node */
- Assert(op->colTypes != NIL);
- return op->colTypes;
- }
- else
- {
- elog(ERROR, "getSetColTypes: unexpected node %d",
- (int) nodeTag(node));
- return NIL; /* keep compiler quiet */
- }
-}
-
-/* Attach column names from a ColumnDef list to a TargetEntry list */
-static void
-applyColumnNames(List *dst, List *src)
-{
- if (length(src) > length(dst))
- elog(ERROR, "CREATE TABLE AS specifies too many column names");
-
- while (src != NIL && dst != NIL)
- {
- TargetEntry *d = (TargetEntry *) lfirst(dst);
- ColumnDef *s = (ColumnDef *) lfirst(src);
-
- Assert(d->resdom && !d->resdom->resjunk);
-
- d->resdom->resname = pstrdup(s->colname);
-
- dst = lnext(dst);
- src = lnext(src);
- }
-}
-
-
-/*
- * transformUpdateStmt -
- * transforms an update statement
- */
-static Query *
-transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
-{
- Query *qry = makeNode(Query);
- Node *qual;
- List *origTargetList;
- List *tl;
-
- qry->commandType = CMD_UPDATE;
- pstate->p_is_update = true;
-
- qry->resultRelation = setTargetTable(pstate, stmt->relation,
- interpretInhOption(stmt->relation->inhOpt),
- true);
-
- /*
- * the FROM clause is non-standard SQL syntax. We used to be able to
- * do this with REPLACE in POSTQUEL so we keep the feature.
- */
- transformFromClause(pstate, stmt->fromClause);
-
- qry->targetList = transformTargetList(pstate, stmt->targetList);
-
- qual = transformWhereClause(pstate, stmt->whereClause);
-
- qry->rtable = pstate->p_rtable;
- qry->jointree = makeFromExpr(pstate->p_joinlist, qual);
-
- qry->hasSubLinks = pstate->p_hasSubLinks;
- qry->hasAggs = pstate->p_hasAggs;
- if (pstate->p_hasAggs)
- parseCheckAggregates(pstate, qry, qual);
-
- /*
- * Now we are done with SELECT-like processing, and can get on with
- * transforming the target list to match the UPDATE target columns.
- */
-
- /* Prepare to assign non-conflicting resnos to resjunk attributes */
- if (pstate->p_last_resno <= pstate->p_target_relation->rd_rel->relnatts)
- pstate->p_last_resno = pstate->p_target_relation->rd_rel->relnatts + 1;
-
- /* Prepare non-junk columns for assignment to target table */
- origTargetList = stmt->targetList;
- foreach(tl, qry->targetList)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Resdom *resnode = tle->resdom;
- ResTarget *origTarget;
-
- if (resnode->resjunk)
- {
- /*
- * Resjunk nodes need no additional processing, but be sure
- * they have names and resnos that do not match any target
- * columns; else rewriter or planner might get confused.
- */
- resnode->resname = "?resjunk?";
- resnode->resno = (AttrNumber) pstate->p_last_resno++;
- continue;
- }
- if (origTargetList == NIL)
- elog(ERROR, "UPDATE target count mismatch --- internal error");
- origTarget = (ResTarget *) lfirst(origTargetList);
- updateTargetListEntry(pstate, tle, origTarget->name,
- attnameAttNum(pstate->p_target_relation,
- origTarget->name),
- origTarget->indirection);
- origTargetList = lnext(origTargetList);
- }
- if (origTargetList != NIL)
- elog(ERROR, "UPDATE target count mismatch --- internal error");
-
- return qry;
-}
-
-/*
- * tranformAlterTableStmt -
- * transform an Alter Table Statement
- */
-static Query *
-transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
- List **extras_before, List **extras_after)
-{
- CreateStmtContext cxt;
- Query *qry;
-
- /*
- * The only subtypes that currently require parse transformation
- * handling are 'A'dd column and Add 'C'onstraint. These largely
- * re-use code from CREATE TABLE.
- */
- switch (stmt->subtype)
- {
- case 'A':
- cxt.stmtType = "ALTER TABLE";
- cxt.relation = stmt->relation;
- cxt.inhRelations = NIL;
- cxt.relOid = RangeVarGetRelid(stmt->relation, false);
- cxt.hasoids = SearchSysCacheExists(ATTNUM,
- ObjectIdGetDatum(cxt.relOid),
- Int16GetDatum(ObjectIdAttributeNumber),
- 0, 0);
- cxt.columns = NIL;
- cxt.ckconstraints = NIL;
- cxt.fkconstraints = NIL;
- cxt.ixconstraints = NIL;
- cxt.blist = NIL;
- cxt.alist = NIL;
- cxt.pkey = NULL;
-
- Assert(IsA(stmt->def, ColumnDef));
- transformColumnDefinition(pstate, &cxt,
- (ColumnDef *) stmt->def);
-
- transformIndexConstraints(pstate, &cxt);
- transformFKConstraints(pstate, &cxt);
-
- ((ColumnDef *) stmt->def)->constraints = cxt.ckconstraints;
- *extras_before = nconc(*extras_before, cxt.blist);
- *extras_after = nconc(cxt.alist, *extras_after);
- break;
-
- case 'C':
- cxt.stmtType = "ALTER TABLE";
- cxt.relation = stmt->relation;
- cxt.inhRelations = NIL;
- cxt.relOid = RangeVarGetRelid(stmt->relation, false);
- cxt.hasoids = SearchSysCacheExists(ATTNUM,
- ObjectIdGetDatum(cxt.relOid),
- Int16GetDatum(ObjectIdAttributeNumber),
- 0, 0);
- cxt.columns = NIL;
- cxt.ckconstraints = NIL;
- cxt.fkconstraints = NIL;
- cxt.ixconstraints = NIL;
- cxt.blist = NIL;
- cxt.alist = NIL;
- cxt.pkey = NULL;
-
- if (IsA(stmt->def, Constraint))
- transformTableConstraint(pstate, &cxt,
- (Constraint *) stmt->def);
- else if (IsA(stmt->def, FkConstraint))
- cxt.fkconstraints = lappend(cxt.fkconstraints, stmt->def);
- else
- elog(ERROR, "Unexpected node type in ALTER TABLE ADD CONSTRAINT");
-
- transformIndexConstraints(pstate, &cxt);
- transformFKConstraints(pstate, &cxt);
-
- Assert(cxt.columns == NIL);
- stmt->def = (Node *) nconc(cxt.ckconstraints, cxt.fkconstraints);
- *extras_before = nconc(*extras_before, cxt.blist);
- *extras_after = nconc(cxt.alist, *extras_after);
- break;
-
- default:
- break;
- }
-
- qry = makeNode(Query);
- qry->commandType = CMD_UTILITY;
- qry->utilityStmt = (Node *) stmt;
-
- return qry;
-}
-
-/* exported so planner can check again after rewriting, query pullup, etc */
-void
-CheckSelectForUpdate(Query *qry)
-{
- if (qry->setOperations)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
- if (qry->distinctClause != NIL)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with DISTINCT clause");
- if (qry->groupClause != NIL)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with GROUP BY clause");
- if (qry->hasAggs)
- elog(ERROR, "SELECT FOR UPDATE is not allowed with AGGREGATE");
-}
-
-static void
-transformForUpdate(Query *qry, List *forUpdate)
-{
- List *rowMarks = qry->rowMarks;
- List *l;
- List *rt;
- Index i;
-
- CheckSelectForUpdate(qry);
-
- if (lfirst(forUpdate) == NULL)
- {
- /* all tables used in query */
- i = 0;
- foreach(rt, qry->rtable)
- {
- RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
-
- ++i;
- if (rte->rtekind == RTE_SUBQUERY)
- {
- /* FOR UPDATE of subquery is propagated to subquery's rels */
- transformForUpdate(rte->subquery, makeList1(NULL));
- }
- else
- {
- if (!intMember(i, rowMarks)) /* avoid duplicates */
- rowMarks = lappendi(rowMarks, i);
- rte->checkForWrite = true;
- }
- }
- }
- else
- {
- /* just the named tables */
- foreach(l, forUpdate)
- {
- char *relname = strVal(lfirst(l));
-
- i = 0;
- foreach(rt, qry->rtable)
- {
- RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
-
- ++i;
- if (strcmp(rte->eref->aliasname, relname) == 0)
- {
- if (rte->rtekind == RTE_SUBQUERY)
- {
- /* propagate to subquery */
- transformForUpdate(rte->subquery, makeList1(NULL));
- }
- else
- {
- if (!intMember(i, rowMarks)) /* avoid duplicates */
- rowMarks = lappendi(rowMarks, i);
- rte->checkForWrite = true;
- }
- break;
- }
- }
- if (rt == NIL)
- elog(ERROR, "FOR UPDATE: relation \"%s\" not found in FROM clause",
- relname);
- }
- }
-
- qry->rowMarks = rowMarks;
-}
-
-
-/*
- * transformFkeyCheckAttrs -
- *
- * Make sure that the attributes of a referenced table
- * belong to a unique (or primary key) constraint.
- */
-static void
-transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid)
-{
- Relation pkrel;
- List *indexoidlist,
- *indexoidscan;
- int i;
- bool found = false;
-
- /*
- * Open the referenced table
- */
- pkrel = heap_openrv(fkconstraint->pktable, AccessShareLock);
-
- if (pkrel->rd_rel->relkind != RELKIND_RELATION)
- elog(ERROR, "Referenced relation \"%s\" is not a table",
- fkconstraint->pktable->relname);
-
- /*
- * Get the list of index OIDs for the table from the relcache, and
- * look up each one in the pg_index syscache for each unique one, and
- * then compare the attributes we were given to those defined.
- */
- indexoidlist = RelationGetIndexList(pkrel);
-
- foreach(indexoidscan, indexoidlist)
- {
- Oid indexoid = lfirsti(indexoidscan);
- HeapTuple indexTuple;
- Form_pg_index indexStruct;
-
- found = false;
- indexTuple = SearchSysCache(INDEXRELID,
- ObjectIdGetDatum(indexoid),
- 0, 0, 0);
- if (!HeapTupleIsValid(indexTuple))
- elog(ERROR, "transformFkeyCheckAttrs: index %u not found",
- indexoid);
- indexStruct = (Form_pg_index) GETSTRUCT(indexTuple);
-
- if (indexStruct->indisunique)
- {
- for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
- ;
- if (i == length(fkconstraint->pk_attrs))
- {
- /* go through the fkconstraint->pk_attrs list */
- List *attrl;
- int attnum = 0;
-
- foreach(attrl, fkconstraint->pk_attrs)
- {
- Ident *attr = lfirst(attrl);
-
- found = false;
- for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
- {
- int pkattno = indexStruct->indkey[i];
-
- if (namestrcmp(attnumAttName(pkrel, pkattno),
- attr->name) == 0)
- {
- pktypoid[attnum++] = attnumTypeId(pkrel, pkattno);
- found = true;
- break;
- }
- }
- if (!found)
- break;
- }
- }
- }
- ReleaseSysCache(indexTuple);
- if (found)
- break;
- }
- if (!found)
- elog(ERROR, "UNIQUE constraint matching given keys for referenced table \"%s\" not found",
- fkconstraint->pktable->relname);
-
- freeList(indexoidlist);
- heap_close(pkrel, AccessShareLock);
-}
-
-
-/*
- * transformFkeyGetPrimaryKey -
- *
- * Try to find the primary key attributes of a referenced table if
- * the column list in the REFERENCES specification was omitted.
- */
-static void
-transformFkeyGetPrimaryKey(FkConstraint *fkconstraint, Oid *pktypoid)
-{
- Relation pkrel;
- List *indexoidlist,
- *indexoidscan;
- HeapTuple indexTuple = NULL;
- Form_pg_index indexStruct = NULL;
- int i;
- int attnum = 0;
-
- /*
- * Open the referenced table
- */
- pkrel = heap_openrv(fkconstraint->pktable, AccessShareLock);
-
- if (pkrel->rd_rel->relkind != RELKIND_RELATION)
- elog(ERROR, "Referenced relation \"%s\" is not a table",
- fkconstraint->pktable->relname);
-
- /*
- * Get the list of index OIDs for the table from the relcache, and
- * look up each one in the pg_index syscache until we find one marked
- * primary key (hopefully there isn't more than one such).
- */
- indexoidlist = RelationGetIndexList(pkrel);
-
- foreach(indexoidscan, indexoidlist)
- {
- Oid indexoid = lfirsti(indexoidscan);
-
- indexTuple = SearchSysCache(INDEXRELID,
- ObjectIdGetDatum(indexoid),
- 0, 0, 0);
- if (!HeapTupleIsValid(indexTuple))
- elog(ERROR, "transformFkeyGetPrimaryKey: index %u not found",
- indexoid);
- indexStruct = (Form_pg_index) GETSTRUCT(indexTuple);
- if (indexStruct->indisprimary)
- break;
- ReleaseSysCache(indexTuple);
- indexStruct = NULL;
- }
-
- freeList(indexoidlist);
-
- /*
- * Check that we found it
- */
- if (indexStruct == NULL)
- elog(ERROR, "PRIMARY KEY for referenced table \"%s\" not found",
- fkconstraint->pktable->relname);
-
- /*
- * Now build the list of PK attributes from the indkey definition
- * using the attribute names of the PK relation descriptor
- */
- for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
- {
- int pkattno = indexStruct->indkey[i];
- Ident *pkattr = makeNode(Ident);
-
- pkattr->name = pstrdup(NameStr(*attnumAttName(pkrel, pkattno)));
- pktypoid[attnum++] = attnumTypeId(pkrel, pkattno);
-
- fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, pkattr);
- }
-
- ReleaseSysCache(indexTuple);
-
- heap_close(pkrel, AccessShareLock);
-}
-
-/*
- * relationHasPrimaryKey -
- *
- * See whether an existing relation has a primary key.
- */
-static bool
-relationHasPrimaryKey(Oid relationOid)
-{
- bool result = false;
- Relation rel;
- List *indexoidlist,
- *indexoidscan;
-
- rel = heap_open(relationOid, AccessShareLock);
-
- /*
- * Get the list of index OIDs for the table from the relcache, and
- * look up each one in the pg_index syscache until we find one marked
- * primary key (hopefully there isn't more than one such).
- */
- indexoidlist = RelationGetIndexList(rel);
-
- foreach(indexoidscan, indexoidlist)
- {
- Oid indexoid = lfirsti(indexoidscan);
- HeapTuple indexTuple;
-
- indexTuple = SearchSysCache(INDEXRELID,
- ObjectIdGetDatum(indexoid),
- 0, 0, 0);
- if (!HeapTupleIsValid(indexTuple))
- elog(ERROR, "relationHasPrimaryKey: index %u not found",
- indexoid);
- result = ((Form_pg_index) GETSTRUCT(indexTuple))->indisprimary;
- ReleaseSysCache(indexTuple);
- if (result)
- break;
- }
-
- freeList(indexoidlist);
-
- heap_close(rel, AccessShareLock);
-
- return result;
-}
-
-/*
- * transformFkeyGetColType -
- *
- * Find a referencing column by name, and return its type OID.
- * Error if it can't be found.
- */
-static Oid
-transformFkeyGetColType(CreateStmtContext *cxt, char *colname)
-{
- List *cols;
- List *inher;
- Oid result;
- Form_pg_attribute sysatt;
-
- /* First look for column among the newly-created columns */
- foreach(cols, cxt->columns)
- {
- ColumnDef *col = lfirst(cols);
-
- if (strcmp(col->colname, colname) == 0)
- return typenameTypeId(col->typename);
- }
- /* Perhaps it's a system column name */
- sysatt = SystemAttributeByName(colname, cxt->hasoids);
- if (sysatt)
- return sysatt->atttypid;
- /* Look for column among inherited columns (if CREATE TABLE case) */
- foreach(inher, cxt->inhRelations)
- {
- RangeVar *inh = lfirst(inher);
- Relation rel;
- int count;
-
- Assert(IsA(inh, RangeVar));
- rel = heap_openrv(inh, AccessShareLock);
- if (rel->rd_rel->relkind != RELKIND_RELATION)
- elog(ERROR, "inherited table \"%s\" is not a relation",
- inh->relname);
- for (count = 0; count < rel->rd_att->natts; count++)
- {
- char *name = NameStr(rel->rd_att->attrs[count]->attname);
-
- if (strcmp(name, colname) == 0)
- {
- result = rel->rd_att->attrs[count]->atttypid;
- heap_close(rel, NoLock);
- return result;
- }
- }
- heap_close(rel, NoLock);
- }
- /* Look for column among existing columns (if ALTER TABLE case) */
- if (OidIsValid(cxt->relOid))
- {
- HeapTuple atttuple;
-
- atttuple = SearchSysCache(ATTNAME,
- ObjectIdGetDatum(cxt->relOid),
- PointerGetDatum(colname),
- 0, 0);
- if (HeapTupleIsValid(atttuple))
- {
- result = ((Form_pg_attribute) GETSTRUCT(atttuple))->atttypid;
- ReleaseSysCache(atttuple);
- return result;
- }
- }
-
- elog(ERROR, "%s: column \"%s\" referenced in foreign key constraint does not exist",
- cxt->stmtType, colname);
- return InvalidOid; /* keep compiler quiet */
-}
-
-/*
- * Preprocess a list of column constraint clauses
- * to attach constraint attributes to their primary constraint nodes
- * and detect inconsistent/misplaced constraint attributes.
- *
- * NOTE: currently, attributes are only supported for FOREIGN KEY primary
- * constraints, but someday they ought to be supported for other constraints.
- */
-static void
-transformConstraintAttrs(List *constraintList)
-{
- Node *lastprimarynode = NULL;
- bool saw_deferrability = false;
- bool saw_initially = false;
- List *clist;
-
- foreach(clist, constraintList)
- {
- Node *node = lfirst(clist);
-
- if (!IsA(node, Constraint))
- {
- lastprimarynode = node;
- /* reset flags for new primary node */
- saw_deferrability = false;
- saw_initially = false;
- }
- else
- {
- Constraint *con = (Constraint *) node;
-
- switch (con->contype)
- {
- case CONSTR_ATTR_DEFERRABLE:
- if (lastprimarynode == NULL ||
- !IsA(lastprimarynode, FkConstraint))
- elog(ERROR, "Misplaced DEFERRABLE clause");
- if (saw_deferrability)
- elog(ERROR, "Multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed");
- saw_deferrability = true;
- ((FkConstraint *) lastprimarynode)->deferrable = true;
- break;
- case CONSTR_ATTR_NOT_DEFERRABLE:
- if (lastprimarynode == NULL ||
- !IsA(lastprimarynode, FkConstraint))
- elog(ERROR, "Misplaced NOT DEFERRABLE clause");
- if (saw_deferrability)
- elog(ERROR, "Multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed");
- saw_deferrability = true;
- ((FkConstraint *) lastprimarynode)->deferrable = false;
- if (saw_initially &&
- ((FkConstraint *) lastprimarynode)->initdeferred)
- elog(ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
- break;
- case CONSTR_ATTR_DEFERRED:
- if (lastprimarynode == NULL ||
- !IsA(lastprimarynode, FkConstraint))
- elog(ERROR, "Misplaced INITIALLY DEFERRED clause");
- if (saw_initially)
- elog(ERROR, "Multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed");
- saw_initially = true;
- ((FkConstraint *) lastprimarynode)->initdeferred = true;
-
- /*
- * If only INITIALLY DEFERRED appears, assume
- * DEFERRABLE
- */
- if (!saw_deferrability)
- ((FkConstraint *) lastprimarynode)->deferrable = true;
- else if (!((FkConstraint *) lastprimarynode)->deferrable)
- elog(ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
- break;
- case CONSTR_ATTR_IMMEDIATE:
- if (lastprimarynode == NULL ||
- !IsA(lastprimarynode, FkConstraint))
- elog(ERROR, "Misplaced INITIALLY IMMEDIATE clause");
- if (saw_initially)
- elog(ERROR, "Multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed");
- saw_initially = true;
- ((FkConstraint *) lastprimarynode)->initdeferred = false;
- break;
- default:
- /* Otherwise it's not an attribute */
- lastprimarynode = node;
- /* reset flags for new primary node */
- saw_deferrability = false;
- saw_initially = false;
- break;
- }
- }
- }
-}
-
-/* Build a FromExpr node */
-static FromExpr *
-makeFromExpr(List *fromlist, Node *quals)
-{
- FromExpr *f = makeNode(FromExpr);
-
- f->fromlist = fromlist;
- f->quals = quals;
- return f;
-}
-
-/*
- * Special handling of type definition for a column
- */
-static void
-transformColumnType(ParseState *pstate, ColumnDef *column)
-{
- TypeName *typename = column->typename;
- Type ctype = typenameType(typename);
-
- /*
- * Is this the name of a complex type? If so, implement it as a set.
- *
- * XXX this is a hangover from ancient Berkeley code that probably
- * doesn't work anymore anyway.
- */
- if (typeTypeRelid(ctype) != InvalidOid)
- {
- /*
- * (Eventually add in here that the set can only contain one
- * element.)
- */
- typename->setof = true;
- }
-
- ReleaseSysCache(ctype);
-}
-
-/*
- * analyzeCreateSchemaStmt -
- * analyzes the "create schema" statement
- *
- * Split the schema element list into individual commands and place
- * them in the result list in an order such that there are no
- * forward references (e.g. GRANT to a table created later in the list).
- *
- * SQL92 also allows constraints to make forward references, so thumb through
- * the table columns and move forward references to a posterior alter-table
- * command.
- *
- * The result is a list of parse nodes that still need to be analyzed ---
- * but we can't analyze the later commands until we've executed the earlier
- * ones, because of possible inter-object references.
- *
- * Note: Called from commands/command.c
- */
-List *
-analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
-{
- CreateSchemaStmtContext cxt;
- List *result;
- List *elements;
-
- cxt.stmtType = "CREATE SCHEMA";
- cxt.schemaname = stmt->schemaname;
- cxt.authid = stmt->authid;
- cxt.tables = NIL;
- cxt.views = NIL;
- cxt.grants = NIL;
- cxt.fwconstraints = NIL;
- cxt.alters = NIL;
- cxt.blist = NIL;
- cxt.alist = NIL;
-
- /*
- * Run through each schema element in the schema element list.
- * Separate statements by type, and do preliminary analysis.
- */
- foreach(elements, stmt->schemaElts)
- {
- Node *element = lfirst(elements);
-
- switch (nodeTag(element))
- {
- case T_CreateStmt:
- {
- CreateStmt *elp = (CreateStmt *) element;
-
- if (elp->relation->schemaname == NULL)
- elp->relation->schemaname = cxt.schemaname;
- else if (strcmp(cxt.schemaname, elp->relation->schemaname) != 0)
- elog(ERROR, "New table specifies a schema (%s)"
- " different from the one being created (%s)",
- elp->relation->schemaname, cxt.schemaname);
-
- /*
- * XXX todo: deal with constraints
- */
-
- cxt.tables = lappend(cxt.tables, element);
- }
- break;
-
- case T_ViewStmt:
- {
- ViewStmt *elp = (ViewStmt *) element;
-
- if (elp->view->schemaname == NULL)
- elp->view->schemaname = cxt.schemaname;
- else if (strcmp(cxt.schemaname, elp->view->schemaname) != 0)
- elog(ERROR, "New view specifies a schema (%s)"
- " different from the one being created (%s)",
- elp->view->schemaname, cxt.schemaname);
-
- /*
- * XXX todo: deal with references between views
- */
-
- cxt.views = lappend(cxt.views, element);
- }
- break;
-
- case T_GrantStmt:
- cxt.grants = lappend(cxt.grants, element);
- break;
-
- default:
- elog(ERROR, "parser: unsupported schema node (internal error)");
- }
- }
-
- result = NIL;
- result = nconc(result, cxt.tables);
- result = nconc(result, cxt.views);
- result = nconc(result, cxt.grants);
-
- return result;
-}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
deleted file mode 100644
index 33fe987686f..00000000000
--- a/src/backend/parser/gram.y
+++ /dev/null
@@ -1,7218 +0,0 @@
-%{
-
-/*#define YYDEBUG 1*/
-/*-------------------------------------------------------------------------
- *
- * gram.y
- * POSTGRES SQL YACC rules/actions
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.333 2002/06/20 20:29:32 momjian Exp $
- *
- * HISTORY
- * AUTHOR DATE MAJOR EVENT
- * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
- * Andrew Yu Oct, 1994 lispy code conversion
- *
- * NOTES
- * CAPITALS are used to represent terminal symbols.
- * non-capitals are used to represent non-terminals.
- * SQL92-specific syntax is separated from plain SQL/Postgres syntax
- * to help isolate the non-extensible portions of the parser.
- *
- * In general, nothing in this file should initiate database accesses
- * nor depend on changeable state (such as SET variables). If you do
- * database accesses, your code will fail when we have aborted the
- * current transaction and are just parsing commands to find the next
- * ROLLBACK or COMMIT. If you make use of SET variables, then you
- * will do the wrong thing in multi-query strings like this:
- * SET SQL_inheritance TO off; SELECT * FROM foo;
- * because the entire string is parsed by gram.y before the SET gets
- * executed. Anything that depends on the database or changeable state
- * should be handled inside parse_analyze() so that it happens at the
- * right time not the wrong time. The handling of SQL_inheritance is
- * a good example.
- *
- * WARNINGS
- * If you use a list, make sure the datum is a node so that the printing
- * routines work.
- *
- * Sometimes we assign constants to makeStrings. Make sure we don't free
- * those.
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <ctype.h>
-
-#include "access/htup.h"
-#include "catalog/index.h"
-#include "catalog/namespace.h"
-#include "catalog/pg_type.h"
-#include "nodes/makefuncs.h"
-#include "nodes/params.h"
-#include "nodes/parsenodes.h"
-#include "parser/gramparse.h"
-#include "storage/lmgr.h"
-#include "utils/numeric.h"
-#include "utils/datetime.h"
-#include "utils/date.h"
-
-#ifdef MULTIBYTE
-#include "mb/pg_wchar.h"
-#else
-#define GetStandardEncoding() 0 /* PG_SQL_ASCII */
-#define GetStandardEncodingName() "SQL_ASCII"
-#endif
-
-extern List *parsetree; /* final parse result is delivered here */
-
-static bool QueryIsRule = FALSE;
-static Oid *param_type_info;
-static int pfunc_num_args;
-
-
-/*
- * If you need access to certain yacc-generated variables and find that
- * they're static by default, uncomment the next line. (this is not a
- * problem, yet.)
- */
-/*#define __YYSCLASS*/
-
-static Node *makeTypeCast(Node *arg, TypeName *typename);
-static Node *makeStringConst(char *str, TypeName *typename);
-static Node *makeIntConst(int val);
-static Node *makeFloatConst(char *str);
-static Node *makeAConst(Value *v);
-static Node *makeRowExpr(List *opr, List *largs, List *rargs);
-static SelectStmt *findLeftmostSelect(SelectStmt *node);
-static void insertSelectOptions(SelectStmt *stmt,
- List *sortClause, List *forUpdate,
- Node *limitOffset, Node *limitCount);
-static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
-static Node *doNegate(Node *n);
-static void doNegateFloat(Value *v);
-
-#define MASK(b) (1 << (b))
-
-%}
-
-
-%union
-{
- int ival;
- char chr;
- char *str;
- const char *keyword;
- bool boolean;
- JoinType jtype;
- List *list;
- Node *node;
- Value *value;
- ColumnRef *columnref;
-
- TypeName *typnam;
- DefElem *defelt;
- SortGroupBy *sortgroupby;
- JoinExpr *jexpr;
- IndexElem *ielem;
- Alias *alias;
- RangeVar *range;
- A_Indices *aind;
- ResTarget *target;
- PrivTarget *privtarget;
-
- InsertStmt *istmt;
- VariableSetStmt *vsetstmt;
-}
-
-%type <node> stmt, schema_stmt,
- AlterDatabaseSetStmt, AlterGroupStmt, AlterSchemaStmt,
- AlterTableStmt, AlterUserStmt, AlterUserSetStmt,
- AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt,
- ConstraintsSetStmt, CopyStmt, CreateAsStmt,
- CreateDomainStmt, CreateGroupStmt, CreatePLangStmt,
- CreateSchemaStmt, CreateSeqStmt, CreateStmt,
- CreateAssertStmt, CreateTrigStmt, CreateUserStmt,
- CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt,
- DropGroupStmt, DropPLangStmt, DropSchemaStmt, DropStmt,
- DropAssertStmt, DropTrigStmt, DropRuleStmt,
- DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt,
- GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt,
- LockStmt, NotifyStmt, OptimizableStmt,
- CreateFunctionStmt, ReindexStmt, RemoveAggrStmt,
- RemoveFuncStmt, RemoveOperStmt, RenameStmt, RevokeStmt,
- RuleActionStmt, RuleActionStmtOrEmpty, RuleStmt,
- SelectStmt, TransactionStmt, TruncateStmt,
- UnlistenStmt, UpdateStmt, VacuumStmt,
- VariableResetStmt, VariableSetStmt, VariableShowStmt,
- ViewStmt, CheckPointStmt
-
-%type <node> select_no_parens, select_with_parens, select_clause,
- simple_select
-
-%type <node> alter_column_default
-%type <ival> add_drop, drop_behavior, opt_drop_behavior
-
-%type <list> createdb_opt_list, copy_opt_list
-%type <defelt> createdb_opt_item, copy_opt_item
-
-%type <ival> opt_lock, lock_type
-%type <boolean> opt_force, opt_or_replace
-
-%type <list> user_list
-
-%type <list> OptGroupList
-%type <defelt> OptGroupElem
-
-%type <list> OptUserList
-%type <defelt> OptUserElem
-
-%type <str> OptSchemaName
-%type <list> OptSchemaEltList
-
-%type <boolean> TriggerActionTime, TriggerForSpec, opt_trusted
-%type <str> opt_lancompiler
-
-%type <str> TriggerEvents
-%type <value> TriggerFuncArg
-
-%type <str> relation_name, copy_file_name,
- database_name, access_method_clause, access_method, attr_name,
- index_name, name, function_name, file_name
-
-%type <list> func_name, handler_name, qual_Op, qual_all_Op, OptUseOp,
- opt_class, opt_validator
-
-%type <range> qualified_name, OptConstrFromTable
-
-%type <str> opt_id, all_Op, MathOp, opt_name, SpecialRuleRelation
-
-%type <str> opt_level, opt_encoding
-%type <node> grantee
-%type <list> grantee_list
-%type <ival> privilege
-%type <list> privileges, privilege_list
-%type <privtarget> privilege_target
-%type <node> function_with_argtypes
-%type <list> function_with_argtypes_list
-%type <chr> TriggerOneEvent
-
-%type <list> stmtblock, stmtmulti,
- OptTableElementList, OptInherit, definition,
- opt_distinct, opt_definition, func_args,
- func_args_list, func_as, createfunc_opt_list
- oper_argtypes, RuleActionList, RuleActionMulti,
- opt_column_list, columnList, opt_name_list,
- sort_clause, sortby_list, index_params, index_list,
- name_list, from_clause, from_list, opt_array_bounds,
- qualified_name_list, any_name, any_name_list,
- any_operator, expr_list, dotted_name, attrs,
- target_list, update_target_list, insert_column_list,
- insert_target_list, def_list, opt_indirection,
- group_clause, TriggerFuncArgs, select_limit,
- opt_select_limit
-
-%type <range> into_clause, OptTempTableName
-
-%type <defelt> createfunc_opt_item
-%type <typnam> func_arg, func_return, func_type, aggr_argtype
-
-%type <boolean> opt_arg, TriggerForType, OptTemp, OptWithOids
-
-%type <list> for_update_clause, opt_for_update_clause, update_list
-%type <boolean> opt_all
-
-%type <node> join_outer, join_qual
-%type <jtype> join_type
-
-%type <list> extract_list, overlay_list, position_list
-%type <list> substr_list, trim_list
-%type <ival> opt_interval
-%type <node> overlay_placing, substr_from, substr_for
-
-%type <boolean> opt_instead, opt_cursor
-%type <boolean> index_opt_unique, opt_verbose, opt_full
-%type <boolean> opt_freeze
-%type <defelt> opt_binary, opt_oids, copy_delimiter
-
-%type <boolean> copy_from
-
-%type <ival> direction, reindex_type, drop_type,
- opt_column, event, comment_type
-
-%type <ival> fetch_how_many
-
-%type <node> select_limit_value, select_offset_value
-
-%type <list> OptSeqList
-%type <defelt> OptSeqElem
-
-%type <istmt> insert_rest
-
-%type <vsetstmt> set_rest
-
-%type <node> OptTableElement, ConstraintElem
-%type <node> columnDef
-%type <defelt> def_elem
-%type <node> def_arg, columnElem, where_clause, insert_column_item,
- a_expr, b_expr, c_expr, AexprConst,
- in_expr, having_clause, func_table
-%type <list> row_descriptor, row_list, in_expr_nodes
-%type <node> row_expr
-%type <node> case_expr, case_arg, when_clause, case_default
-%type <list> when_clause_list
-%type <ival> sub_type
-%type <list> OptCreateAs, CreateAsList
-%type <node> CreateAsElement
-%type <value> NumericOnly, FloatOnly, IntegerOnly
-%type <columnref> columnref
-%type <alias> alias_clause
-%type <sortgroupby> sortby
-%type <ielem> index_elem, func_index
-%type <node> table_ref
-%type <jexpr> joined_table
-%type <range> relation_expr
-%type <target> target_el, insert_target_el, update_target_el
-
-%type <typnam> Typename, SimpleTypename, ConstTypename,
- GenericType, Numeric, opt_float, Character,
- ConstDatetime, ConstInterval, Bit
-%type <str> character
-%type <str> extract_arg
-%type <str> opt_charset, opt_collate
-%type <ival> opt_numeric, opt_decimal
-%type <boolean> opt_varying, opt_timezone
-
-%type <ival> Iconst
-%type <str> Sconst, comment_text
-%type <str> UserId, opt_boolean, ColId_or_Sconst
-%type <list> var_list, var_list_or_default
-%type <str> ColId, ColLabel, type_name
-%type <node> var_value, zone_value
-
-%type <keyword> unreserved_keyword, func_name_keyword
-%type <keyword> col_name_keyword, reserved_keyword
-
-%type <node> TableConstraint
-%type <list> ColQualList
-%type <node> ColConstraint, ColConstraintElem, ConstraintAttr
-%type <ival> key_actions, key_delete, key_update, key_reference
-%type <str> key_match
-%type <ival> ConstraintAttributeSpec, ConstraintDeferrabilitySpec,
- ConstraintTimeSpec
-
-%type <list> constraints_set_list
-%type <boolean> constraints_set_mode
-
-
-/*
- * If you make any token changes, update the keyword table in
- * parser/keywords.c and add new keywords to the appropriate one of
- * the reserved-or-not-so-reserved keyword lists, below.
- */
-
-/* ordinary key words in alphabetical order */
-%token <keyword> ABORT_TRANS, ABSOLUTE, ACCESS, ACTION, ADD, AFTER,
- AGGREGATE, ALL, ALTER, ANALYSE, ANALYZE, AND, ANY, AS, ASC,
- ASSERTION, AT, AUTHORIZATION,
-
- BACKWARD, BEFORE, BEGIN_TRANS, BETWEEN, BIGINT, BINARY, BIT, BOTH,
- BOOLEAN, BY,
-
- CACHE, CALLED, CASCADE, CASE, CAST, CHAIN, CHAR_P,
- CHARACTER, CHARACTERISTICS, CHECK, CHECKPOINT, CLOSE,
- CLUSTER, COALESCE, COLLATE, COLUMN, COMMENT, COMMIT,
- COMMITTED, CONSTRAINT, CONSTRAINTS, COPY, CREATE, CREATEDB,
- CREATEUSER, CROSS, CURRENT_DATE, CURRENT_TIME,
- CURRENT_TIMESTAMP, CURRENT_USER, CURSOR, CYCLE,
-
- DATABASE, DAY_P, DEC, DECIMAL, DECLARE, DEFAULT,
- DEFERRABLE, DEFERRED, DEFINER, DELETE_P, DELIMITER, DELIMITERS,
- DESC, DISTINCT, DO, DOMAIN_P, DOUBLE, DROP,
-
- EACH, ELSE, ENCODING, ENCRYPTED, END_TRANS, ESCAPE, EXCEPT,
- EXCLUSIVE, EXECUTE, EXISTS, EXPLAIN, EXTERNAL, EXTRACT,
-
- FALSE_P, FETCH, FLOAT_P, FOR, FORCE, FOREIGN, FORWARD,
- FREEZE, FROM, FULL, FUNCTION,
-
- GET, GLOBAL, GRANT, GROUP_P,
-
- HANDLER, HAVING, HOUR_P,
-
- ILIKE, IMMEDIATE, IMMUTABLE, IMPLICIT, IN_P, INCREMENT,
- INDEX, INHERITS, INITIALLY, INNER_P, INOUT, INPUT,
- INSENSITIVE, INSERT, INSTEAD, INT, INTEGER, INTERSECT,
- INTERVAL, INTO, INVOKER, IS, ISNULL, ISOLATION,
-
- JOIN,
- KEY,
-
- LANCOMPILER, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LIMIT,
- LISTEN, LOAD, LOCAL, LOCALTIME, LOCALTIMESTAMP, LOCATION,
- LOCK_P,
-
- MATCH, MAXVALUE, MINUTE_P, MINVALUE, MODE, MONTH_P, MOVE,
-
- NAMES, NATIONAL, NATURAL, NCHAR, NEW, NEXT, NO, NOCREATEDB,
- NOCREATEUSER, NONE, NOT, NOTHING, NOTIFY, NOTNULL, NULL_P,
- NULLIF, NUMERIC,
-
- OF, OFF, OFFSET, OIDS, OLD, ON, ONLY, OPERATOR, OPTION, OR,
- ORDER, OUT_P, OUTER_P, OVERLAPS, OVERLAY, OWNER,
-
- PARTIAL, PASSWORD, PATH_P, PENDANT, PLACING, POSITION,
- PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE,
- PROCEDURAL,
-
- READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE,
- RESET, RESTRICT, RETURNS, REVOKE, RIGHT, ROLLBACK, ROW,
- RULE,
-
- SCHEMA, SCROLL, SECOND_P, SECURITY, SELECT, SEQUENCE,
- SERIALIZABLE, SESSION, SESSION_USER, SET, SETOF, SHARE,
- SHOW, SIMILAR, SMALLINT, SOME, STABLE, START, STATEMENT,
- STATISTICS, STDIN, STDOUT, STORAGE, STRICT, SUBSTRING,
- SYSID,
-
- TABLE, TEMP, TEMPLATE, TEMPORARY, THEN, TIME, TIMESTAMP,
- TO, TOAST, TRAILING, TRANSACTION, TRIGGER, TRIM, TRUE_P,
- TRUNCATE, TRUSTED, TYPE_P,
-
- UNENCRYPTED, UNION, UNIQUE, UNKNOWN, UNLISTEN, UNTIL,
- UPDATE, USAGE, USER, USING,
-
- VACUUM, VALID, VALIDATOR, VALUES, VARCHAR, VARYING,
- VERBOSE, VERSION, VIEW, VOLATILE,
-
- WHEN, WHERE, WITH, WITHOUT, WORK,
-
- YEAR_P,
-
- ZONE
-
-/* The grammar thinks these are keywords, but they are not in the keywords.c
- * list and so can never be entered directly. The filter in parser.c
- * creates these tokens when required.
- */
-%token UNIONJOIN
-
-/* Special keywords, not in the query language - see the "lex" file */
-%token <str> IDENT, FCONST, SCONST, BITCONST, Op
-%token <ival> ICONST, PARAM
-
-/* these are not real. they are here so that they get generated as #define's*/
-%token OP
-
-/* precedence: lowest to highest */
-%left UNION EXCEPT
-%left INTERSECT
-%left JOIN UNIONJOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
-%left OR
-%left AND
-%right NOT
-%right '='
-%nonassoc '<' '>'
-%nonassoc LIKE ILIKE SIMILAR
-%nonassoc ESCAPE
-%nonassoc OVERLAPS
-%nonassoc BETWEEN
-%nonassoc IN_P
-%left POSTFIXOP /* dummy for postfix Op rules */
-%left Op OPERATOR /* multi-character ops and user-defined operators */
-%nonassoc NOTNULL
-%nonassoc ISNULL
-%nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
-%left '+' '-'
-%left '*' '/' '%'
-%left '^'
-/* Unary Operators */
-%left AT ZONE /* sets precedence for AT TIME ZONE */
-%right UMINUS
-%left '[' ']'
-%left '(' ')'
-%left COLLATE
-%left TYPECAST
-%left '.'
-%%
-
-/*
- * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
- * psql already handles such cases, but other interfaces don't.
- * bjm 1999/10/05
- */
-stmtblock: stmtmulti { parsetree = $1; }
- ;
-
-/* the thrashing around here is to discard "empty" statements... */
-stmtmulti: stmtmulti ';' stmt
- { if ($3 != (Node *)NULL)
- $$ = lappend($1, $3);
- else
- $$ = $1;
- }
- | stmt
- { if ($1 != (Node *)NULL)
- $$ = makeList1($1);
- else
- $$ = NIL;
- }
- ;
-
-stmt :
- AlterDatabaseSetStmt
- | AlterGroupStmt
- | AlterSchemaStmt
- | AlterTableStmt
- | AlterUserStmt
- | AlterUserSetStmt
- | ClosePortalStmt
- | CopyStmt
- | CreateStmt
- | CreateAsStmt
- | CreateDomainStmt
- | CreateFunctionStmt
- | CreateSchemaStmt
- | CreateGroupStmt
- | CreateSeqStmt
- | CreatePLangStmt
- | CreateAssertStmt
- | CreateTrigStmt
- | CreateUserStmt
- | ClusterStmt
- | DefineStmt
- | DropStmt
- | DropSchemaStmt
- | TruncateStmt
- | CommentStmt
- | DropGroupStmt
- | DropPLangStmt
- | DropAssertStmt
- | DropTrigStmt
- | DropRuleStmt
- | DropUserStmt
- | ExplainStmt
- | FetchStmt
- | GrantStmt
- | IndexStmt
- | ListenStmt
- | UnlistenStmt
- | LockStmt
- | NotifyStmt
- | ReindexStmt
- | RemoveAggrStmt
- | RemoveOperStmt
- | RemoveFuncStmt
- | RenameStmt
- | RevokeStmt
- | OptimizableStmt
- | RuleStmt
- | TransactionStmt
- | ViewStmt
- | LoadStmt
- | CreatedbStmt
- | DropdbStmt
- | VacuumStmt
- | AnalyzeStmt
- | VariableSetStmt
- | VariableShowStmt
- | VariableResetStmt
- | ConstraintsSetStmt
- | CheckPointStmt
- | /*EMPTY*/
- { $$ = (Node *)NULL; }
- ;
-
-/*****************************************************************************
- *
- * Create a new Postgres DBMS user
- *
- *
- *****************************************************************************/
-
-CreateUserStmt:
- CREATE USER UserId opt_with OptUserList
- {
- CreateUserStmt *n = makeNode(CreateUserStmt);
- n->user = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-
-opt_with: WITH {}
- | /*EMPTY*/ {}
- ;
-
-/*****************************************************************************
- *
- * Alter a postgresql DBMS user
- *
- *
- *****************************************************************************/
-
-AlterUserStmt:
- ALTER USER UserId opt_with OptUserList
- {
- AlterUserStmt *n = makeNode(AlterUserStmt);
- n->user = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-
-AlterUserSetStmt:
- ALTER USER UserId SET set_rest
- {
- AlterUserSetStmt *n = makeNode(AlterUserSetStmt);
- n->user = $3;
- n->variable = $5->name;
- n->value = $5->args;
- $$ = (Node *)n;
- }
- | ALTER USER UserId VariableResetStmt
- {
- AlterUserSetStmt *n = makeNode(AlterUserSetStmt);
- n->user = $3;
- n->variable = ((VariableResetStmt *)$4)->name;
- n->value = NIL;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * Drop a postgresql DBMS user
- *
- *
- *****************************************************************************/
-
-DropUserStmt:
- DROP USER user_list
- {
- DropUserStmt *n = makeNode(DropUserStmt);
- n->users = $3;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * Options for CREATE USER and ALTER USER
- */
-OptUserList:
- OptUserList OptUserElem { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
-
-OptUserElem:
- PASSWORD Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "password";
- $$->arg = (Node *)makeString($2);
- }
- | ENCRYPTED PASSWORD Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "encryptedPassword";
- $$->arg = (Node *)makeString($3);
- }
- | UNENCRYPTED PASSWORD Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "unencryptedPassword";
- $$->arg = (Node *)makeString($3);
- }
- | SYSID Iconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "sysid";
- $$->arg = (Node *)makeInteger($2);
- }
- | CREATEDB
- {
- $$ = makeNode(DefElem);
- $$->defname = "createdb";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | NOCREATEDB
- {
- $$ = makeNode(DefElem);
- $$->defname = "createdb";
- $$->arg = (Node *)makeInteger(FALSE);
- }
- | CREATEUSER
- {
- $$ = makeNode(DefElem);
- $$->defname = "createuser";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | NOCREATEUSER
- {
- $$ = makeNode(DefElem);
- $$->defname = "createuser";
- $$->arg = (Node *)makeInteger(FALSE);
- }
- | IN_P GROUP_P user_list
- {
- $$ = makeNode(DefElem);
- $$->defname = "groupElts";
- $$->arg = (Node *)$3;
- }
- | VALID UNTIL Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "validUntil";
- $$->arg = (Node *)makeString($3);
- }
- ;
-
-user_list: user_list ',' UserId { $$ = lappend($1, makeString($3)); }
- | UserId { $$ = makeList1(makeString($1)); }
- ;
-
-
-
-/*****************************************************************************
- *
- * Create a postgresql group
- *
- *
- *****************************************************************************/
-
-CreateGroupStmt:
- CREATE GROUP_P UserId opt_with OptGroupList
- {
- CreateGroupStmt *n = makeNode(CreateGroupStmt);
- n->name = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * Options for CREATE GROUP
- */
-OptGroupList:
- OptGroupList OptGroupElem { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
-
-OptGroupElem:
- USER user_list
- {
- $$ = makeNode(DefElem);
- $$->defname = "userElts";
- $$->arg = (Node *)$2;
- }
- | SYSID Iconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "sysid";
- $$->arg = (Node *)makeInteger($2);
- }
- ;
-
-
-/*****************************************************************************
- *
- * Alter a postgresql group
- *
- *
- *****************************************************************************/
-
-AlterGroupStmt:
- ALTER GROUP_P UserId add_drop USER user_list
- {
- AlterGroupStmt *n = makeNode(AlterGroupStmt);
- n->name = $3;
- n->action = $4;
- n->listUsers = $6;
- $$ = (Node *)n;
- }
- ;
-
-add_drop: ADD { $$ = +1; }
- | DROP { $$ = -1; }
- ;
-
-
-/*****************************************************************************
- *
- * Drop a postgresql group
- *
- *
- *****************************************************************************/
-
-DropGroupStmt:
- DROP GROUP_P UserId
- {
- DropGroupStmt *n = makeNode(DropGroupStmt);
- n->name = $3;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * Manipulate a schema
- *
- *
- *****************************************************************************/
-
-CreateSchemaStmt:
- CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* One can omit the schema name or the authorization id. */
- if ($3 != NULL)
- n->schemaname = $3;
- else
- n->schemaname = $5;
- n->authid = $5;
- n->schemaElts = $6;
- $$ = (Node *)n;
- }
- | CREATE SCHEMA ColId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* ...but not both */
- n->schemaname = $3;
- n->authid = NULL;
- n->schemaElts = $4;
- $$ = (Node *)n;
- }
- ;
-
-AlterSchemaStmt:
- ALTER SCHEMA ColId
- {
- elog(ERROR, "ALTER SCHEMA not yet supported");
- }
- ;
-
-DropSchemaStmt:
- DROP SCHEMA ColId
- {
- elog(ERROR, "DROP SCHEMA not yet supported");
- }
- ;
-
-OptSchemaName:
- ColId { $$ = $1; }
- | /* EMPTY */ { $$ = NULL; }
- ;
-
-OptSchemaEltList:
- OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
-
-/*
- * schema_stmt are the ones that can show up inside a CREATE SCHEMA
- * statement (in addition to by themselves).
- */
-schema_stmt:
- CreateStmt
- | GrantStmt
- | ViewStmt
- ;
-
-
-/*****************************************************************************
- *
- * Set PG internal variable
- * SET name TO 'var_value'
- * Include SQL92 syntax (thomas 1997-10-22):
- * SET TIME ZONE 'var_value'
- *
- *****************************************************************************/
-
-VariableSetStmt:
- SET set_rest
- {
- VariableSetStmt *n = $2;
- n->is_local = false;
- $$ = (Node *) n;
- }
- | SET LOCAL set_rest
- {
- VariableSetStmt *n = $3;
- n->is_local = true;
- $$ = (Node *) n;
- }
- | SET SESSION set_rest
- {
- VariableSetStmt *n = $3;
- n->is_local = false;
- $$ = (Node *) n;
- }
- ;
-
-set_rest: ColId TO var_list_or_default
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = $1;
- n->args = $3;
- $$ = n;
- }
- | ColId '=' var_list_or_default
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = $1;
- n->args = $3;
- $$ = n;
- }
- | TIME ZONE zone_value
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "timezone";
- if ($3 != NULL)
- n->args = makeList1($3);
- $$ = n;
- }
- | TRANSACTION ISOLATION LEVEL opt_level
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "TRANSACTION ISOLATION LEVEL";
- n->args = makeList1(makeStringConst($4, NULL));
- $$ = n;
- }
- | SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL opt_level
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "default_transaction_isolation";
- n->args = makeList1(makeStringConst($7, NULL));
- $$ = n;
- }
- | NAMES opt_encoding
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "client_encoding";
- if ($2 != NULL)
- n->args = makeList1(makeStringConst($2, NULL));
- $$ = n;
- }
- | SESSION AUTHORIZATION ColId_or_Sconst
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "session_authorization";
- n->args = makeList1(makeStringConst($3, NULL));
- $$ = n;
- }
- | SESSION AUTHORIZATION DEFAULT
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->name = "session_authorization";
- n->args = NIL;
- $$ = n;
- }
- ;
-
-var_list_or_default:
- var_list { $$ = $1; }
- | DEFAULT { $$ = NIL; }
- ;
-
-var_list: var_value { $$ = makeList1($1); }
- | var_list ',' var_value { $$ = lappend($1, $3); }
- ;
-
-var_value: opt_boolean
- { $$ = makeStringConst($1, NULL); }
- | ColId_or_Sconst
- { $$ = makeStringConst($1, NULL); }
- | NumericOnly
- { $$ = makeAConst($1); }
- ;
-
-opt_level: READ COMMITTED { $$ = "read committed"; }
- | SERIALIZABLE { $$ = "serializable"; }
- ;
-
-opt_boolean:
- TRUE_P { $$ = "true"; }
- | FALSE_P { $$ = "false"; }
- | ON { $$ = "on"; }
- | OFF { $$ = "off"; }
- ;
-
-/* Timezone values can be:
- * - a string such as 'pst8pdt'
- * - an identifier such as "pst8pdt"
- * - an integer or floating point number
- * - a time interval per SQL99
- * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
- * so use IDENT and reject anything which is a reserved word.
- */
-zone_value:
- Sconst
- {
- $$ = makeStringConst($1, NULL);
- }
- | IDENT
- {
- $$ = makeStringConst($1, NULL);
- }
- | ConstInterval Sconst opt_interval
- {
- A_Const *n = (A_Const *) makeStringConst($2, $1);
- if ($3 != -1)
- {
- if (($3 & ~(MASK(HOUR) | MASK(MINUTE))) != 0)
- elog(ERROR,
- "Time zone interval must be HOUR or HOUR TO MINUTE");
- n->typename->typmod = ((($3 & 0x7FFF) << 16) | 0xFFFF);
- }
- $$ = (Node *)n;
- }
- | ConstInterval '(' Iconst ')' Sconst opt_interval
- {
- A_Const *n = (A_Const *) makeStringConst($5, $1);
- if (($3 < 0) || ($3 > MAX_INTERVAL_PRECISION))
- elog(ERROR,
- "INTERVAL(%d) precision must be between %d and %d",
- $3, 0, MAX_INTERVAL_PRECISION);
- if ($6 != -1)
- {
- if (($6 & ~(MASK(HOUR) | MASK(MINUTE))) != 0)
- elog(ERROR,
- "Time zone interval must be HOUR or HOUR TO MINUTE");
- n->typename->typmod = ((($6 & 0x7FFF) << 16) | $3);
- }
- else
- {
- n->typename->typmod = ((0x7FFF << 16) | $3);
- }
-
- $$ = (Node *)n;
- }
- | NumericOnly { $$ = makeAConst($1); }
- | DEFAULT { $$ = NULL; }
- | LOCAL { $$ = NULL; }
- ;
-
-opt_encoding:
- Sconst { $$ = $1; }
- | DEFAULT { $$ = NULL; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-ColId_or_Sconst:
- ColId { $$ = $1; }
- | SCONST { $$ = $1; }
- ;
-
-
-VariableShowStmt:
- SHOW ColId
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = $2;
- $$ = (Node *) n;
- }
- | SHOW TIME ZONE
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "timezone";
- $$ = (Node *) n;
- }
- | SHOW TRANSACTION ISOLATION LEVEL
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "TRANSACTION ISOLATION LEVEL";
- $$ = (Node *) n;
- }
- | SHOW SESSION AUTHORIZATION
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "session_authorization";
- $$ = (Node *) n;
- }
- | SHOW ALL
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "all";
- $$ = (Node *) n;
- }
- ;
-
-VariableResetStmt:
- RESET ColId
- {
- VariableResetStmt *n = makeNode(VariableResetStmt);
- n->name = $2;
- $$ = (Node *) n;
- }
- | RESET TIME ZONE
- {
- VariableResetStmt *n = makeNode(VariableResetStmt);
- n->name = "timezone";
- $$ = (Node *) n;
- }
- | RESET TRANSACTION ISOLATION LEVEL
- {
- VariableResetStmt *n = makeNode(VariableResetStmt);
- n->name = "TRANSACTION ISOLATION LEVEL";
- $$ = (Node *) n;
- }
- | RESET SESSION AUTHORIZATION
- {
- VariableResetStmt *n = makeNode(VariableResetStmt);
- n->name = "session_authorization";
- $$ = (Node *) n;
- }
- | RESET ALL
- {
- VariableResetStmt *n = makeNode(VariableResetStmt);
- n->name = "all";
- $$ = (Node *) n;
- }
- ;
-
-
-ConstraintsSetStmt:
- SET CONSTRAINTS constraints_set_list constraints_set_mode
- {
- ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
- n->constraints = $3;
- n->deferred = $4;
- $$ = (Node *) n;
- }
- ;
-
-constraints_set_list:
- ALL { $$ = NIL; }
- | name_list { $$ = $1; }
- ;
-
-constraints_set_mode:
- DEFERRED { $$ = TRUE; }
- | IMMEDIATE { $$ = FALSE; }
- ;
-
-
-/*
- * Checkpoint statement
- */
-CheckPointStmt:
- CHECKPOINT
- {
- CheckPointStmt *n = makeNode(CheckPointStmt);
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * ALTER TABLE variations
- *
- *****************************************************************************/
-
-AlterTableStmt:
- /* ALTER TABLE <relation> ADD [COLUMN] <coldef> */
- ALTER TABLE relation_expr ADD opt_column columnDef
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'A';
- n->relation = $3;
- n->def = $6;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ALTER [COLUMN] <colname>
- * {SET DEFAULT <expr>|DROP DEFAULT}
- */
- | ALTER TABLE relation_expr ALTER opt_column
- ColId alter_column_default
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'T';
- n->relation = $3;
- n->name = $6;
- n->def = $7;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ALTER [COLUMN] <colname>
- * DROP NOT NULL
- */
- | ALTER TABLE relation_expr ALTER opt_column
- ColId DROP NOT NULL_P
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'N';
- n->relation = $3;
- n->name = $6;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ALTER [COLUMN] <colname>
- * SET NOT NULL
- */
- | ALTER TABLE relation_expr ALTER opt_column ColId
- SET NOT NULL_P
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'O';
- n->relation = $3;
- n->name = $6;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ALTER [COLUMN] <colname>
- * SET STATISTICS <Iconst>
- */
- | ALTER TABLE relation_expr ALTER opt_column ColId
- SET STATISTICS Iconst
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'S';
- n->relation = $3;
- n->name = $6;
- n->def = (Node *) makeInteger($9);
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ALTER [COLUMN] <colname>
- * SET STORAGE <storagemode>
- */
- | ALTER TABLE relation_expr ALTER opt_column ColId
- SET STORAGE ColId
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'M';
- n->relation = $3;
- n->name = $6;
- n->def = (Node *) makeString($9);
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> DROP [COLUMN] <colname>
- * {RESTRICT|CASCADE}
- */
- | ALTER TABLE relation_expr DROP opt_column ColId drop_behavior
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'D';
- n->relation = $3;
- n->name = $6;
- n->behavior = $7;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> ADD CONSTRAINT ... */
- | ALTER TABLE relation_expr ADD TableConstraint
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'C';
- n->relation = $3;
- n->def = $5;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <relation> DROP CONSTRAINT <name>
- * {RESTRICT|CASCADE}
- */
- | ALTER TABLE relation_expr DROP CONSTRAINT name drop_behavior
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'X';
- n->relation = $3;
- n->name = $6;
- n->behavior = $7;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <name> CREATE TOAST TABLE */
- | ALTER TABLE qualified_name CREATE TOAST TABLE
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'E';
- $3->inhOpt = INH_NO;
- n->relation = $3;
- $$ = (Node *)n;
- }
- /* ALTER TABLE <name> OWNER TO UserId */
- | ALTER TABLE qualified_name OWNER TO UserId
- {
- AlterTableStmt *n = makeNode(AlterTableStmt);
- n->subtype = 'U';
- $3->inhOpt = INH_NO;
- n->relation = $3;
- n->name = $6;
- $$ = (Node *)n;
- }
- ;
-
-alter_column_default:
- SET DEFAULT a_expr
- {
- /* Treat SET DEFAULT NULL the same as DROP DEFAULT */
- if (exprIsNullConstant($3))
- $$ = NULL;
- else
- $$ = $3;
- }
- | DROP DEFAULT { $$ = NULL; }
- ;
-
-drop_behavior:
- CASCADE { $$ = CASCADE; }
- | RESTRICT { $$ = RESTRICT; }
- ;
-
-opt_drop_behavior:
- CASCADE { $$ = CASCADE; }
- | RESTRICT { $$ = RESTRICT; }
- | /* EMPTY */ { $$ = RESTRICT; /* default */ }
- ;
-
-
-
-/*****************************************************************************
- *
- * QUERY :
- * close <optname>
- *
- *****************************************************************************/
-
-ClosePortalStmt:
- CLOSE opt_id
- {
- ClosePortalStmt *n = makeNode(ClosePortalStmt);
- n->portalname = $2;
- $$ = (Node *)n;
- }
- ;
-
-opt_id: ColId { $$ = $1; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY :
- * COPY <relname> FROM/TO [WITH options]
- *
- * BINARY, OIDS, and DELIMITERS kept in old locations
- * for backward compatibility. 2002-06-18
- *
- *****************************************************************************/
-
-CopyStmt: COPY opt_binary qualified_name opt_oids copy_from
- copy_file_name copy_delimiter opt_with copy_opt_list
- {
- CopyStmt *n = makeNode(CopyStmt);
- n->relation = $3;
- n->is_from = $5;
- n->filename = $6;
-
- n->options = NIL;
- /* Concatenate user-supplied flags */
- if ($2)
- n->options = lappend(n->options, $2);
- if ($4)
- n->options = lappend(n->options, $4);
- if ($7)
- n->options = lappend(n->options, $7);
- if ($9)
- n->options = nconc(n->options, $9);
- $$ = (Node *)n;
- }
- ;
-
-copy_from:
- FROM { $$ = TRUE; }
- | TO { $$ = FALSE; }
- ;
-
-/*
- * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
- * used depends on the direction. (It really doesn't make sense to copy from
- * stdout. We silently correct the "typo". - AY 9/94
- */
-copy_file_name:
- Sconst { $$ = $1; }
- | STDIN { $$ = NULL; }
- | STDOUT { $$ = NULL; }
- ;
-
-
-
-copy_opt_list:
- copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
-
-
-copy_opt_item:
- BINARY
- {
- $$ = makeNode(DefElem);
- $$->defname = "binary";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | OIDS
- {
- $$ = makeNode(DefElem);
- $$->defname = "oids";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | DELIMITER opt_as Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "delimiter";
- $$->arg = (Node *)makeString($3);
- }
- | NULL_P opt_as Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "null";
- $$->arg = (Node *)makeString($3);
- }
- ;
-
-/* The following exist for backward compatibility */
-
-opt_binary:
- BINARY
- {
- $$ = makeNode(DefElem);
- $$->defname = "binary";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-opt_oids:
- WITH OIDS
- {
- $$ = makeNode(DefElem);
- $$->defname = "oids";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-copy_delimiter:
- /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
- opt_using DELIMITERS Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "delimiter";
- $$->arg = (Node *)makeString($3);
- }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-opt_using:
- USING {}
- | /*EMPTY*/ {}
- ;
-
-
-/*****************************************************************************
- *
- * QUERY :
- * CREATE relname
- *
- *****************************************************************************/
-
-CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
- OptInherit OptWithOids
- {
- CreateStmt *n = makeNode(CreateStmt);
- $4->istemp = $2;
- n->relation = $4;
- n->tableElts = $6;
- n->inhRelations = $8;
- n->constraints = NIL;
- n->hasoids = $9;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * Redundancy here is needed to avoid shift/reduce conflicts,
- * since TEMP is not a reserved word. See also OptTempTableName.
- */
-OptTemp: TEMPORARY { $$ = TRUE; }
- | TEMP { $$ = TRUE; }
- | LOCAL TEMPORARY { $$ = TRUE; }
- | LOCAL TEMP { $$ = TRUE; }
- | GLOBAL TEMPORARY
- {
- elog(ERROR,
- "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = TRUE;
- }
- | GLOBAL TEMP
- {
- elog(ERROR,
- "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = TRUE;
- }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-OptTableElementList:
- OptTableElementList ',' OptTableElement
- {
- if ($3 != NULL)
- $$ = lappend($1, $3);
- else
- $$ = $1;
- }
- | OptTableElement
- {
- if ($1 != NULL)
- $$ = makeList1($1);
- else
- $$ = NIL;
- }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-OptTableElement:
- columnDef { $$ = $1; }
- | TableConstraint { $$ = $1; }
- ;
-
-columnDef: ColId Typename ColQualList opt_collate
- {
- ColumnDef *n = makeNode(ColumnDef);
- n->colname = $1;
- n->typename = $2;
- n->constraints = $3;
-
- if ($4 != NULL)
- elog(NOTICE,
- "CREATE TABLE / COLLATE %s not yet implemented; "
- "clause ignored", $4);
-
- $$ = (Node *)n;
- }
- ;
-
-ColQualList:
- ColQualList ColConstraint { $$ = lappend($1, $2); }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-ColConstraint:
- CONSTRAINT name ColConstraintElem
- {
- switch (nodeTag($3))
- {
- case T_Constraint:
- {
- Constraint *n = (Constraint *)$3;
- n->name = $2;
- }
- break;
- case T_FkConstraint:
- {
- FkConstraint *n = (FkConstraint *)$3;
- n->constr_name = $2;
- }
- break;
- default:
- break;
- }
- $$ = $3;
- }
- | ColConstraintElem { $$ = $1; }
- | ConstraintAttr { $$ = $1; }
- ;
-
-/* DEFAULT NULL is already the default for Postgres.
- * But define it here and carry it forward into the system
- * to make it explicit.
- * - thomas 1998-09-13
- *
- * WITH NULL and NULL are not SQL92-standard syntax elements,
- * so leave them out. Use DEFAULT NULL to explicitly indicate
- * that a column may have that value. WITH NULL leads to
- * shift/reduce conflicts with WITH TIME ZONE anyway.
- * - thomas 1999-01-08
- *
- * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
- * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
- * or be part of a_expr NOT LIKE or similar constructs).
- */
-ColConstraintElem:
- NOT NULL_P
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_NOTNULL;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | NULL_P
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_NULL;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | UNIQUE
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_UNIQUE;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | PRIMARY KEY
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_PRIMARY;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | CHECK '(' a_expr ')'
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_CHECK;
- n->name = NULL;
- n->raw_expr = $3;
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | DEFAULT b_expr
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_DEFAULT;
- n->name = NULL;
- if (exprIsNullConstant($2))
- {
- /* DEFAULT NULL should be reported as empty expr */
- n->raw_expr = NULL;
- }
- else
- {
- n->raw_expr = $2;
- }
- n->cooked_expr = NULL;
- n->keys = NULL;
- $$ = (Node *)n;
- }
- | REFERENCES qualified_name opt_column_list key_match key_actions
- {
- FkConstraint *n = makeNode(FkConstraint);
- n->constr_name = NULL;
- n->pktable = $2;
- n->fk_attrs = NIL;
- n->pk_attrs = $3;
- n->match_type = $4;
- n->actions = $5;
- n->deferrable = FALSE;
- n->initdeferred = FALSE;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * ConstraintAttr represents constraint attributes, which we parse as if
- * they were independent constraint clauses, in order to avoid shift/reduce
- * conflicts (since NOT might start either an independent NOT NULL clause
- * or an attribute). analyze.c is responsible for attaching the attribute
- * information to the preceding "real" constraint node, and for complaining
- * if attribute clauses appear in the wrong place or wrong combinations.
- *
- * See also ConstraintAttributeSpec, which can be used in places where
- * there is no parsing conflict.
- */
-ConstraintAttr:
- DEFERRABLE
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_ATTR_DEFERRABLE;
- $$ = (Node *)n;
- }
- | NOT DEFERRABLE
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
- $$ = (Node *)n;
- }
- | INITIALLY DEFERRED
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_ATTR_DEFERRED;
- $$ = (Node *)n;
- }
- | INITIALLY IMMEDIATE
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_ATTR_IMMEDIATE;
- $$ = (Node *)n;
- }
- ;
-
-
-/* ConstraintElem specifies constraint syntax which is not embedded into
- * a column definition. ColConstraintElem specifies the embedded form.
- * - thomas 1997-12-03
- */
-TableConstraint:
- CONSTRAINT name ConstraintElem
- {
- switch (nodeTag($3))
- {
- case T_Constraint:
- {
- Constraint *n = (Constraint *)$3;
- n->name = $2;
- }
- break;
- case T_FkConstraint:
- {
- FkConstraint *n = (FkConstraint *)$3;
- n->constr_name = $2;
- }
- break;
- default:
- break;
- }
- $$ = $3;
- }
- | ConstraintElem { $$ = $1; }
- ;
-
-ConstraintElem:
- CHECK '(' a_expr ')'
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_CHECK;
- n->name = NULL;
- n->raw_expr = $3;
- n->cooked_expr = NULL;
- $$ = (Node *)n;
- }
- | UNIQUE '(' columnList ')'
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_UNIQUE;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = $3;
- $$ = (Node *)n;
- }
- | PRIMARY KEY '(' columnList ')'
- {
- Constraint *n = makeNode(Constraint);
- n->contype = CONSTR_PRIMARY;
- n->name = NULL;
- n->raw_expr = NULL;
- n->cooked_expr = NULL;
- n->keys = $4;
- $$ = (Node *)n;
- }
- | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
- opt_column_list
- key_match key_actions ConstraintAttributeSpec
- {
- FkConstraint *n = makeNode(FkConstraint);
- n->constr_name = NULL;
- n->pktable = $7;
- n->fk_attrs = $4;
- n->pk_attrs = $8;
- n->match_type = $9;
- n->actions = $10;
- n->deferrable = ($11 & 1) != 0;
- n->initdeferred = ($11 & 2) != 0;
- $$ = (Node *)n;
- }
- ;
-
-opt_column_list:
- '(' columnList ')' { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-columnList:
- columnElem { $$ = makeList1($1); }
- | columnList ',' columnElem { $$ = lappend($1, $3); }
- ;
-
-columnElem: ColId
- {
- Ident *id = makeNode(Ident);
- id->name = $1;
- $$ = (Node *)id;
- }
- ;
-
-key_match: MATCH FULL { $$ = "FULL"; }
- | MATCH PARTIAL
- {
- elog(ERROR, "FOREIGN KEY/MATCH PARTIAL not yet implemented");
- $$ = "PARTIAL";
- }
- | /*EMPTY*/
- {
- $$ = "UNSPECIFIED";
- }
- ;
-
-key_actions:
- key_delete { $$ = $1; }
- | key_update { $$ = $1; }
- | key_delete key_update { $$ = $1 | $2; }
- | key_update key_delete { $$ = $1 | $2; }
- | /*EMPTY*/ { $$ = 0; }
- ;
-
-key_delete: ON DELETE_P key_reference
- { $$ = $3 << FKCONSTR_ON_DELETE_SHIFT; }
- ;
-
-key_update: ON UPDATE key_reference
- { $$ = $3 << FKCONSTR_ON_UPDATE_SHIFT; }
- ;
-
-key_reference:
- NO ACTION { $$ = FKCONSTR_ON_KEY_NOACTION; }
- | RESTRICT { $$ = FKCONSTR_ON_KEY_RESTRICT; }
- | CASCADE { $$ = FKCONSTR_ON_KEY_CASCADE; }
- | SET NULL_P { $$ = FKCONSTR_ON_KEY_SETNULL; }
- | SET DEFAULT { $$ = FKCONSTR_ON_KEY_SETDEFAULT; }
- ;
-
-OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-OptWithOids:
- WITH OIDS { $$ = TRUE; }
- | WITHOUT OIDS { $$ = FALSE; }
- | /*EMPTY*/ { $$ = TRUE; }
- ;
-
-
-/*
- * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
- * SELECT ... INTO.
- */
-
-CreateAsStmt:
- CREATE OptTemp TABLE qualified_name OptCreateAs AS SelectStmt
- {
- /*
- * When the SelectStmt is a set-operation tree, we must
- * stuff the INTO information into the leftmost component
- * Select, because that's where analyze.c will expect
- * to find it. Similarly, the output column names must
- * be attached to that Select's target list.
- */
- SelectStmt *n = findLeftmostSelect((SelectStmt *) $7);
- if (n->into != NULL)
- elog(ERROR, "CREATE TABLE AS may not specify INTO");
- $4->istemp = $2;
- n->into = $4;
- n->intoColNames = $5;
- $$ = $7;
- }
- ;
-
-OptCreateAs:
- '(' CreateAsList ')' { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-CreateAsList:
- CreateAsElement { $$ = makeList1($1); }
- | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
- ;
-
-CreateAsElement:
- ColId
- {
- ColumnDef *n = makeNode(ColumnDef);
- n->colname = $1;
- n->typename = NULL;
- n->raw_default = NULL;
- n->cooked_default = NULL;
- n->is_not_null = FALSE;
- n->constraints = NULL;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY :
- * CREATE SEQUENCE seqname
- *
- *****************************************************************************/
-
-CreateSeqStmt:
- CREATE OptTemp SEQUENCE qualified_name OptSeqList
- {
- CreateSeqStmt *n = makeNode(CreateSeqStmt);
- $4->istemp = $2;
- n->sequence = $4;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-OptSeqList: OptSeqList OptSeqElem { $$ = lappend($1, $2); }
- | { $$ = NIL; }
- ;
-
-OptSeqElem: CACHE NumericOnly
- {
- $$ = makeNode(DefElem);
- $$->defname = "cache";
- $$->arg = (Node *)$2;
- }
- | CYCLE
- {
- $$ = makeNode(DefElem);
- $$->defname = "cycle";
- $$->arg = (Node *)NULL;
- }
- | INCREMENT NumericOnly
- {
- $$ = makeNode(DefElem);
- $$->defname = "increment";
- $$->arg = (Node *)$2;
- }
- | MAXVALUE NumericOnly
- {
- $$ = makeNode(DefElem);
- $$->defname = "maxvalue";
- $$->arg = (Node *)$2;
- }
- | MINVALUE NumericOnly
- {
- $$ = makeNode(DefElem);
- $$->defname = "minvalue";
- $$->arg = (Node *)$2;
- }
- | START NumericOnly
- {
- $$ = makeNode(DefElem);
- $$->defname = "start";
- $$->arg = (Node *)$2;
- }
- ;
-
-NumericOnly:
- FloatOnly { $$ = $1; }
- | IntegerOnly { $$ = $1; }
- ;
-
-FloatOnly: FCONST { $$ = makeFloat($1); }
- | '-' FCONST
- {
- $$ = makeFloat($2);
- doNegateFloat($$);
- }
- ;
-
-IntegerOnly:
- Iconst
- {
- $$ = makeInteger($1);
- }
- | '-' Iconst
- {
- $$ = makeInteger($2);
- $$->val.ival = - $$->val.ival;
- }
- ;
-
-/*****************************************************************************
- *
- * QUERIES :
- * CREATE PROCEDURAL LANGUAGE ...
- * DROP PROCEDURAL LANGUAGE ...
- *
- *****************************************************************************/
-
-CreatePLangStmt:
- CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
- HANDLER handler_name opt_validator opt_lancompiler
- {
- CreatePLangStmt *n = makeNode(CreatePLangStmt);
- n->plname = $5;
- n->plhandler = $7;
- n->plvalidator = $8;
- n->plcompiler = $9;
- n->pltrusted = $2;
- $$ = (Node *)n;
- }
- ;
-
-opt_trusted:
- TRUSTED { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-/* This ought to be just func_name, but that causes reduce/reduce conflicts
- * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
- * Work around by using name and dotted_name separately.
- */
-handler_name:
- name
- { $$ = makeList1(makeString($1)); }
- | dotted_name { $$ = $1; }
- ;
-
-opt_lancompiler:
- LANCOMPILER Sconst { $$ = $2; }
- | /*EMPTY*/ { $$ = ""; }
- ;
-
-opt_validator:
- VALIDATOR handler_name { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-DropPLangStmt:
- DROP opt_procedural LANGUAGE ColId_or_Sconst
- {
- DropPLangStmt *n = makeNode(DropPLangStmt);
- n->plname = $4;
- $$ = (Node *)n;
- }
- ;
-
-opt_procedural:
- PROCEDURAL {}
- | /*EMPTY*/ {}
- ;
-
-/*****************************************************************************
- *
- * QUERIES :
- * CREATE TRIGGER ...
- * DROP TRIGGER ...
- *
- *****************************************************************************/
-
-CreateTrigStmt:
- CREATE TRIGGER name TriggerActionTime TriggerEvents ON
- qualified_name TriggerForSpec EXECUTE PROCEDURE
- func_name '(' TriggerFuncArgs ')'
- {
- CreateTrigStmt *n = makeNode(CreateTrigStmt);
- n->trigname = $3;
- n->relation = $7;
- n->funcname = $11;
- n->args = $13;
- n->before = $4;
- n->row = $8;
- memcpy (n->actions, $5, 4);
- n->lang = NULL; /* unused */
- n->text = NULL; /* unused */
- n->attr = NULL; /* unused */
- n->when = NULL; /* unused */
-
- n->isconstraint = FALSE;
- n->deferrable = FALSE;
- n->initdeferred = FALSE;
- n->constrrel = NULL;
- $$ = (Node *)n;
- }
- | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
- qualified_name OptConstrFromTable
- ConstraintAttributeSpec
- FOR EACH ROW EXECUTE PROCEDURE
- func_name '(' TriggerFuncArgs ')'
- {
- CreateTrigStmt *n = makeNode(CreateTrigStmt);
- n->trigname = $4;
- n->relation = $8;
- n->funcname = $16;
- n->args = $18;
- n->before = FALSE;
- n->row = TRUE;
- memcpy (n->actions, $6, 4);
- n->lang = NULL; /* unused */
- n->text = NULL; /* unused */
- n->attr = NULL; /* unused */
- n->when = NULL; /* unused */
-
- n->isconstraint = TRUE;
- n->deferrable = ($10 & 1) != 0;
- n->initdeferred = ($10 & 2) != 0;
-
- n->constrrel = $9;
- $$ = (Node *)n;
- }
- ;
-
-TriggerActionTime:
- BEFORE { $$ = TRUE; }
- | AFTER { $$ = FALSE; }
- ;
-
-TriggerEvents:
- TriggerOneEvent
- {
- char *e = palloc (4);
- e[0] = $1; e[1] = 0; $$ = e;
- }
- | TriggerOneEvent OR TriggerOneEvent
- {
- char *e = palloc (4);
- e[0] = $1; e[1] = $3; e[2] = 0; $$ = e;
- }
- | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
- {
- char *e = palloc (4);
- e[0] = $1; e[1] = $3; e[2] = $5; e[3] = 0;
- $$ = e;
- }
- ;
-
-TriggerOneEvent:
- INSERT { $$ = 'i'; }
- | DELETE_P { $$ = 'd'; }
- | UPDATE { $$ = 'u'; }
- ;
-
-TriggerForSpec:
- FOR TriggerForOpt TriggerForType
- {
- $$ = $3;
- }
- ;
-
-TriggerForOpt:
- EACH {}
- | /*EMPTY*/ {}
- ;
-
-TriggerForType:
- ROW { $$ = TRUE; }
- | STATEMENT { $$ = FALSE; }
- ;
-
-TriggerFuncArgs:
- TriggerFuncArg { $$ = makeList1($1); }
- | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-TriggerFuncArg:
- ICONST
- {
- char buf[64];
- sprintf (buf, "%d", $1);
- $$ = makeString(pstrdup(buf));
- }
- | FCONST { $$ = makeString($1); }
- | Sconst { $$ = makeString($1); }
- | BITCONST { $$ = makeString($1); }
- | ColId { $$ = makeString($1); }
- ;
-
-OptConstrFromTable:
- FROM qualified_name { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-ConstraintAttributeSpec:
- ConstraintDeferrabilitySpec
- { $$ = $1; }
- | ConstraintDeferrabilitySpec ConstraintTimeSpec
- {
- if ($1 == 0 && $2 != 0)
- elog(ERROR,
- "INITIALLY DEFERRED constraint must be DEFERRABLE");
- $$ = $1 | $2;
- }
- | ConstraintTimeSpec
- {
- if ($1 != 0)
- $$ = 3;
- else
- $$ = 0;
- }
- | ConstraintTimeSpec ConstraintDeferrabilitySpec
- {
- if ($2 == 0 && $1 != 0)
- elog(ERROR,
- "INITIALLY DEFERRED constraint must be DEFERRABLE");
- $$ = $1 | $2;
- }
- | /*EMPTY*/
- { $$ = 0; }
- ;
-
-ConstraintDeferrabilitySpec:
- NOT DEFERRABLE { $$ = 0; }
- | DEFERRABLE { $$ = 1; }
- ;
-
-ConstraintTimeSpec:
- INITIALLY IMMEDIATE { $$ = 0; }
- | INITIALLY DEFERRED { $$ = 2; }
- ;
-
-
-DropTrigStmt:
- DROP TRIGGER name ON qualified_name
- {
- DropPropertyStmt *n = makeNode(DropPropertyStmt);
- n->relation = $5;
- n->property = $3;
- n->removeType = DROP_TRIGGER;
- $$ = (Node *) n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERIES :
- * CREATE ASSERTION ...
- * DROP ASSERTION ...
- *
- *****************************************************************************/
-
-CreateAssertStmt:
- CREATE ASSERTION name CHECK '(' a_expr ')'
- ConstraintAttributeSpec
- {
- CreateTrigStmt *n = makeNode(CreateTrigStmt);
- n->trigname = $3;
- n->args = makeList1($6);
- n->isconstraint = TRUE;
- n->deferrable = ($8 & 1) != 0;
- n->initdeferred = ($8 & 2) != 0;
-
- elog(ERROR, "CREATE ASSERTION is not yet supported");
-
- $$ = (Node *)n;
- }
- ;
-
-DropAssertStmt:
- DROP ASSERTION name
- {
- DropPropertyStmt *n = makeNode(DropPropertyStmt);
- n->relation = NULL;
- n->property = $3;
- n->removeType = DROP_TRIGGER;
- elog(ERROR, "DROP ASSERTION is not yet supported");
- $$ = (Node *) n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY :
- * define (aggregate,operator,type)
- *
- *****************************************************************************/
-
-DefineStmt:
- CREATE AGGREGATE func_name definition
- {
- DefineStmt *n = makeNode(DefineStmt);
- n->defType = AGGREGATE;
- n->defnames = $3;
- n->definition = $4;
- $$ = (Node *)n;
- }
- | CREATE OPERATOR any_operator definition
- {
- DefineStmt *n = makeNode(DefineStmt);
- n->defType = OPERATOR;
- n->defnames = $3;
- n->definition = $4;
- $$ = (Node *)n;
- }
- | CREATE TYPE_P any_name definition
- {
- DefineStmt *n = makeNode(DefineStmt);
- n->defType = TYPE_P;
- n->defnames = $3;
- n->definition = $4;
- $$ = (Node *)n;
- }
- | CREATE CHARACTER SET opt_as any_name GET definition opt_collate
- {
- DefineStmt *n = makeNode(DefineStmt);
- n->defType = CHARACTER;
- n->defnames = $5;
- n->definition = $7;
- $$ = (Node *)n;
- }
- ;
-
-definition: '(' def_list ')' { $$ = $2; }
- ;
-
-def_list: def_elem { $$ = makeList1($1); }
- | def_list ',' def_elem { $$ = lappend($1, $3); }
- ;
-
-def_elem: ColLabel '=' def_arg
- {
- $$ = makeNode(DefElem);
- $$->defname = $1;
- $$->arg = (Node *)$3;
- }
- | ColLabel
- {
- $$ = makeNode(DefElem);
- $$->defname = $1;
- $$->arg = (Node *)NULL;
- }
- ;
-
-/* Note: any simple identifier will be returned as a type name! */
-def_arg: func_return { $$ = (Node *)$1; }
- | all_Op { $$ = (Node *)makeString($1); }
- | NumericOnly { $$ = (Node *)$1; }
- | Sconst { $$ = (Node *)makeString($1); }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- *
- * DROP itemtype itemname [, itemname ...]
- *
- *****************************************************************************/
-
-DropStmt: DROP drop_type any_name_list opt_drop_behavior
- {
- DropStmt *n = makeNode(DropStmt);
- n->removeType = $2;
- n->objects = $3;
- n->behavior = $4;
- $$ = (Node *)n;
- }
- ;
-
-drop_type: TABLE { $$ = DROP_TABLE; }
- | SEQUENCE { $$ = DROP_SEQUENCE; }
- | VIEW { $$ = DROP_VIEW; }
- | INDEX { $$ = DROP_INDEX; }
- | TYPE_P { $$ = DROP_TYPE; }
- | DOMAIN_P { $$ = DROP_DOMAIN; }
- ;
-
-any_name_list:
- any_name { $$ = makeList1($1); }
- | any_name_list ',' any_name { $$ = lappend($1, $3); }
- ;
-
-any_name: ColId { $$ = makeList1(makeString($1)); }
- | dotted_name { $$ = $1; }
- ;
-
-/*****************************************************************************
- *
- * QUERY:
- * truncate table relname
- *
- *****************************************************************************/
-
-TruncateStmt:
- TRUNCATE opt_table qualified_name
- {
- TruncateStmt *n = makeNode(TruncateStmt);
- n->relation = $3;
- $$ = (Node *)n;
- }
- ;
-
-/*****************************************************************************
- *
- * The COMMENT ON statement can take different forms based upon the type of
- * the object associated with the comment. The form of the statement is:
- *
- * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW ]
- * <objname> | AGGREGATE <aggname> (<aggtype>) | FUNCTION
- * <funcname> (arg1, arg2, ...) | OPERATOR <op>
- * (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON
- * <relname> | RULE <rulename> ON <relname> ] IS 'text'
- *
- *****************************************************************************/
-
-CommentStmt:
- COMMENT ON comment_type any_name IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = $3;
- n->objname = $4;
- n->objargs = NIL;
- n->comment = $6;
- $$ = (Node *) n;
- }
- | COMMENT ON AGGREGATE func_name '(' aggr_argtype ')'
- IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = AGGREGATE;
- n->objname = $4;
- n->objargs = makeList1($6);
- n->comment = $9;
- $$ = (Node *) n;
- }
- | COMMENT ON FUNCTION func_name func_args IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = FUNCTION;
- n->objname = $4;
- n->objargs = $5;
- n->comment = $7;
- $$ = (Node *) n;
- }
- | COMMENT ON OPERATOR any_operator '(' oper_argtypes ')'
- IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = OPERATOR;
- n->objname = $4;
- n->objargs = $6;
- n->comment = $9;
- $$ = (Node *) n;
- }
- | COMMENT ON TRIGGER name ON any_name IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = TRIGGER;
- n->objname = lappend($6, makeString($4));
- n->objargs = NIL;
- n->comment = $8;
- $$ = (Node *) n;
- }
- | COMMENT ON RULE name ON any_name IS comment_text
- {
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = RULE;
- n->objname = lappend($6, makeString($4));
- n->objargs = NIL;
- n->comment = $8;
- $$ = (Node *) n;
- }
- | COMMENT ON RULE name IS comment_text
- {
- /* Obsolete syntax supported for awhile for compatibility */
- CommentStmt *n = makeNode(CommentStmt);
- n->objtype = RULE;
- n->objname = makeList1(makeString($4));
- n->objargs = NIL;
- n->comment = $6;
- $$ = (Node *) n;
- }
- ;
-
-comment_type:
- COLUMN { $$ = COLUMN; }
- | DATABASE { $$ = DATABASE; }
- | SCHEMA { $$ = SCHEMA; }
- | INDEX { $$ = INDEX; }
- | SEQUENCE { $$ = SEQUENCE; }
- | TABLE { $$ = TABLE; }
- | DOMAIN_P { $$ = TYPE_P; }
- | TYPE_P { $$ = TYPE_P; }
- | VIEW { $$ = VIEW; }
- ;
-
-comment_text:
- Sconst { $$ = $1; }
- | NULL_P { $$ = NULL; }
- ;
-
-/*****************************************************************************
- *
- * QUERY:
- * fetch/move [forward | backward] [ # | all ] [ in <portalname> ]
- * fetch [ forward | backward | absolute | relative ]
- * [ # | all | next | prior ] [ [ in | from ] <portalname> ]
- *
- *****************************************************************************/
-
-FetchStmt: FETCH direction fetch_how_many from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- if ($2 == RELATIVE)
- {
- if ($3 == 0)
- elog(ERROR,
- "FETCH / RELATIVE at current position is not supported");
- $2 = FORWARD;
- }
- if ($3 < 0)
- {
- $3 = -$3;
- $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
- }
- n->direction = $2;
- n->howMany = $3;
- n->portalname = $5;
- n->ismove = FALSE;
- $$ = (Node *)n;
- }
- | FETCH fetch_how_many from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- if ($2 < 0)
- {
- n->howMany = -$2;
- n->direction = BACKWARD;
- }
- else
- {
- n->direction = FORWARD;
- n->howMany = $2;
- }
- n->portalname = $4;
- n->ismove = FALSE;
- $$ = (Node *)n;
- }
- | FETCH direction from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- if ($2 == RELATIVE)
- {
- $2 = FORWARD;
- }
- n->direction = $2;
- n->howMany = 1;
- n->portalname = $4;
- n->ismove = FALSE;
- $$ = (Node *)n;
- }
- | FETCH from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- n->direction = FORWARD;
- n->howMany = 1;
- n->portalname = $3;
- n->ismove = FALSE;
- $$ = (Node *)n;
- }
- | FETCH name
- {
- FetchStmt *n = makeNode(FetchStmt);
- n->direction = FORWARD;
- n->howMany = 1;
- n->portalname = $2;
- n->ismove = FALSE;
- $$ = (Node *)n;
- }
- | MOVE direction fetch_how_many from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- if ($3 < 0)
- {
- $3 = -$3;
- $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
- }
- n->direction = $2;
- n->howMany = $3;
- n->portalname = $5;
- n->ismove = TRUE;
- $$ = (Node *)n;
- }
- | MOVE fetch_how_many from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- if ($2 < 0)
- {
- n->howMany = -$2;
- n->direction = BACKWARD;
- }
- else
- {
- n->direction = FORWARD;
- n->howMany = $2;
- }
- n->portalname = $4;
- n->ismove = TRUE;
- $$ = (Node *)n;
- }
- | MOVE direction from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- n->direction = $2;
- n->howMany = 1;
- n->portalname = $4;
- n->ismove = TRUE;
- $$ = (Node *)n;
- }
- | MOVE from_in name
- {
- FetchStmt *n = makeNode(FetchStmt);
- n->direction = FORWARD;
- n->howMany = 1;
- n->portalname = $3;
- n->ismove = TRUE;
- $$ = (Node *)n;
- }
- | MOVE name
- {
- FetchStmt *n = makeNode(FetchStmt);
- n->direction = FORWARD;
- n->howMany = 1;
- n->portalname = $2;
- n->ismove = TRUE;
- $$ = (Node *)n;
- }
- ;
-
-direction: FORWARD { $$ = FORWARD; }
- | BACKWARD { $$ = BACKWARD; }
- | RELATIVE { $$ = RELATIVE; }
- | ABSOLUTE
- {
- elog(NOTICE,
- "FETCH / ABSOLUTE not supported, using RELATIVE");
- $$ = RELATIVE;
- }
- ;
-
-fetch_how_many:
- Iconst { $$ = $1; }
- | '-' Iconst { $$ = - $2; }
- /* 0 means fetch all tuples*/
- | ALL { $$ = 0; }
- | NEXT { $$ = 1; }
- | PRIOR { $$ = -1; }
- ;
-
-from_in: IN_P {}
- | FROM {}
- ;
-
-
-/*****************************************************************************
- *
- * GRANT and REVOKE statements
- *
- *****************************************************************************/
-
-GrantStmt: GRANT privileges ON privilege_target TO grantee_list
- opt_grant_grant_option
- {
- GrantStmt *n = makeNode(GrantStmt);
- n->is_grant = true;
- n->privileges = $2;
- n->objtype = ($4)->objtype;
- n->objects = ($4)->objs;
- n->grantees = $6;
- $$ = (Node*)n;
- }
- ;
-
-RevokeStmt: REVOKE opt_revoke_grant_option privileges ON privilege_target
- FROM grantee_list
- {
- GrantStmt *n = makeNode(GrantStmt);
- n->is_grant = false;
- n->privileges = $3;
- n->objtype = ($5)->objtype;
- n->objects = ($5)->objs;
- n->grantees = $7;
- $$ = (Node *)n;
- }
- ;
-
-
-/* either ALL [PRIVILEGES] or a list of individual privileges */
-privileges: privilege_list { $$ = $1; }
- | ALL { $$ = makeListi1(ACL_ALL_RIGHTS); }
- | ALL PRIVILEGES { $$ = makeListi1(ACL_ALL_RIGHTS); }
- ;
-
-privilege_list:
- privilege { $$ = makeListi1($1); }
- | privilege_list ',' privilege { $$ = lappendi($1, $3); }
- ;
-
-/* Not all of these privilege types apply to all objects, but that
- * gets sorted out later.
- */
-privilege: SELECT { $$ = ACL_SELECT; }
- | INSERT { $$ = ACL_INSERT; }
- | UPDATE { $$ = ACL_UPDATE; }
- | DELETE_P { $$ = ACL_DELETE; }
- | RULE { $$ = ACL_RULE; }
- | REFERENCES { $$ = ACL_REFERENCES; }
- | TRIGGER { $$ = ACL_TRIGGER; }
- | EXECUTE { $$ = ACL_EXECUTE; }
- | USAGE { $$ = ACL_USAGE; }
- | CREATE { $$ = ACL_CREATE; }
- | TEMPORARY { $$ = ACL_CREATE_TEMP; }
- | TEMP { $$ = ACL_CREATE_TEMP; }
- ;
-
-
-/* Don't bother trying to fold the first two rules into one using
- opt_table. You're going to get conflicts. */
-privilege_target:
- qualified_name_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_RELATION;
- n->objs = $1;
- $$ = n;
- }
- | TABLE qualified_name_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_RELATION;
- n->objs = $2;
- $$ = n;
- }
- | FUNCTION function_with_argtypes_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_FUNCTION;
- n->objs = $2;
- $$ = n;
- }
- | DATABASE name_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_DATABASE;
- n->objs = $2;
- $$ = n;
- }
- | LANGUAGE name_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_LANGUAGE;
- n->objs = $2;
- $$ = n;
- }
- | SCHEMA name_list
- {
- PrivTarget *n = makeNode(PrivTarget);
- n->objtype = ACL_OBJECT_NAMESPACE;
- n->objs = $2;
- $$ = n;
- }
- ;
-
-
-grantee_list:
- grantee { $$ = makeList1($1); }
- | grantee_list ',' grantee { $$ = lappend($1, $3); }
- ;
-
-grantee: ColId
- {
- PrivGrantee *n = makeNode(PrivGrantee);
- /* This hack lets us avoid reserving PUBLIC as a keyword*/
- if (strcmp($1, "public") == 0)
- n->username = NULL;
- else
- n->username = $1;
- n->groupname = NULL;
- $$ = (Node *)n;
- }
- | GROUP_P ColId
- {
- PrivGrantee *n = makeNode(PrivGrantee);
- /* Treat GROUP PUBLIC as a synonym for PUBLIC */
- if (strcmp($2, "public") == 0)
- n->groupname = NULL;
- else
- n->groupname = $2;
- n->username = NULL;
- $$ = (Node *)n;
- }
- ;
-
-
-opt_grant_grant_option:
- WITH GRANT OPTION
- {
- elog(ERROR, "grant options are not implemented");
- }
- | /*EMPTY*/
- ;
-
-opt_revoke_grant_option:
- GRANT OPTION FOR
- {
- elog(ERROR, "grant options are not implemented");
- }
- | /*EMPTY*/
- ;
-
-
-function_with_argtypes_list:
- function_with_argtypes { $$ = makeList1($1); }
- | function_with_argtypes_list ',' function_with_argtypes
- { $$ = lappend($1, $3); }
- ;
-
-function_with_argtypes:
- func_name func_args
- {
- FuncWithArgs *n = makeNode(FuncWithArgs);
- n->funcname = $1;
- n->funcargs = $2;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * create index <indexname> on <relname>
- * [ using <access> ] "(" (<col> with <op>)+ ")"
- * [ where <predicate> ]
- *
- *****************************************************************************/
-
-IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name
- access_method_clause '(' index_params ')' where_clause
- {
- IndexStmt *n = makeNode(IndexStmt);
- n->unique = $2;
- n->idxname = $4;
- n->relation = $6;
- n->accessMethod = $7;
- n->indexParams = $9;
- n->whereClause = $11;
- $$ = (Node *)n;
- }
- ;
-
-index_opt_unique:
- UNIQUE { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-access_method_clause:
- USING access_method { $$ = $2; }
- /* If btree changes as our default, update pg_get_indexdef() */
- | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
- ;
-
-index_params:
- index_list { $$ = $1; }
- | func_index { $$ = makeList1($1); }
- ;
-
-index_list: index_elem { $$ = makeList1($1); }
- | index_list ',' index_elem { $$ = lappend($1, $3); }
- ;
-
-func_index: func_name '(' name_list ')' opt_class
- {
- $$ = makeNode(IndexElem);
- $$->name = NULL;
- $$->funcname = $1;
- $$->args = $3;
- $$->opclass = $5;
- }
- ;
-
-index_elem: attr_name opt_class
- {
- $$ = makeNode(IndexElem);
- $$->name = $1;
- $$->funcname = NIL;
- $$->args = NIL;
- $$->opclass = $2;
- }
- ;
-
-opt_class: any_name
- {
- /*
- * Release 7.0 removed network_ops, timespan_ops, and
- * datetime_ops, so we suppress it from being passed to
- * the parser so the default *_ops is used. This can be
- * removed in some later release. bjm 2000/02/07
- *
- * Release 7.1 removes lztext_ops, so suppress that too
- * for a while. tgl 2000/07/30
- *
- * Release 7.2 renames timestamp_ops to timestamptz_ops,
- * so suppress that too for awhile. I'm starting to
- * think we need a better approach. tgl 2000/10/01
- */
- if (length($1) == 1)
- {
- char *claname = strVal(lfirst($1));
-
- if (strcmp(claname, "network_ops") != 0 &&
- strcmp(claname, "timespan_ops") != 0 &&
- strcmp(claname, "datetime_ops") != 0 &&
- strcmp(claname, "lztext_ops") != 0 &&
- strcmp(claname, "timestamp_ops") != 0)
- $$ = $1;
- else
- $$ = NIL;
- }
- else
- $$ = $1;
- }
- | USING any_name { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-/*****************************************************************************
- *
- * QUERY:
- * execute recipe <recipeName>
- *
- *****************************************************************************/
-
-/* NOT USED
-RecipeStmt: EXECUTE RECIPE recipe_name
- {
- RecipeStmt *n = makeNode(RecipeStmt);
- n->recipeName = $3;
- $$ = (Node *)n;
- }
- ;
-*/
-
-/*****************************************************************************
- *
- * QUERY:
- * create [or replace] function <fname>
- * [(<type-1> { , <type-n>})]
- * returns <type-r>
- * as <filename or code in language as appropriate>
- * language <lang> [with parameters]
- *
- *****************************************************************************/
-
-CreateFunctionStmt:
- CREATE opt_or_replace FUNCTION func_name func_args
- RETURNS func_return createfunc_opt_list opt_definition
- {
- CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
- n->replace = $2;
- n->funcname = $4;
- n->argTypes = $5;
- n->returnType = $7;
- n->options = $8;
- n->withClause = $9;
- $$ = (Node *)n;
- }
- ;
-
-opt_or_replace:
- OR REPLACE { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-func_args: '(' func_args_list ')' { $$ = $2; }
- | '(' ')' { $$ = NIL; }
- ;
-
-func_args_list:
- func_arg { $$ = makeList1($1); }
- | func_args_list ',' func_arg { $$ = lappend($1, $3); }
- ;
-
-func_arg: opt_arg func_type
- {
- /* We can catch over-specified arguments here if we want to,
- * but for now better to silently swallow typmod, etc.
- * - thomas 2000-03-22
- */
- $$ = $2;
- }
- | func_type { $$ = $1; }
- ;
-
-opt_arg: IN_P { $$ = FALSE; }
- | OUT_P
- {
- elog(ERROR,
- "CREATE FUNCTION / OUT parameters are not supported");
- $$ = TRUE;
- }
- | INOUT
- {
- elog(ERROR,
- "CREATE FUNCTION / INOUT parameters are not supported");
- $$ = FALSE;
- }
- ;
-
-func_return:
- func_type
- {
- /* We can catch over-specified arguments here if we want to,
- * but for now better to silently swallow typmod, etc.
- * - thomas 2000-03-22
- */
- $$ = $1;
- }
- ;
-
-/*
- * We would like to make the second production here be ColId attrs etc,
- * but that causes reduce/reduce conflicts. type_name is next best choice.
- */
-func_type: Typename { $$ = $1; }
- | type_name attrs '%' TYPE_P
- {
- $$ = makeNode(TypeName);
- $$->names = lcons(makeString($1), $2);
- $$->pct_type = true;
- $$->typmod = -1;
- }
- ;
-
-
-createfunc_opt_list:
- /* Must be at least one to prevent conflict */
- createfunc_opt_item { $$ = makeList1($1); }
- | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
- ;
-
-createfunc_opt_item:
- AS func_as
- {
- $$ = makeNode(DefElem);
- $$->defname = "as";
- $$->arg = (Node *)$2;
- }
- | LANGUAGE ColId_or_Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "language";
- $$->arg = (Node *)makeString($2);
- }
- | IMMUTABLE
- {
- $$ = makeNode(DefElem);
- $$->defname = "volatility";
- $$->arg = (Node *)makeString("immutable");
- }
- | STABLE
- {
- $$ = makeNode(DefElem);
- $$->defname = "volatility";
- $$->arg = (Node *)makeString("stable");
- }
- | VOLATILE
- {
- $$ = makeNode(DefElem);
- $$->defname = "volatility";
- $$->arg = (Node *)makeString("volatile");
- }
- | CALLED ON NULL_P INPUT
- {
- $$ = makeNode(DefElem);
- $$->defname = "strict";
- $$->arg = (Node *)makeInteger(FALSE);
- }
- | RETURNS NULL_P ON NULL_P INPUT
- {
- $$ = makeNode(DefElem);
- $$->defname = "strict";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | STRICT
- {
- $$ = makeNode(DefElem);
- $$->defname = "strict";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | EXTERNAL SECURITY DEFINER
- {
- $$ = makeNode(DefElem);
- $$->defname = "security";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | EXTERNAL SECURITY INVOKER
- {
- $$ = makeNode(DefElem);
- $$->defname = "security";
- $$->arg = (Node *)makeInteger(FALSE);
- }
- | SECURITY DEFINER
- {
- $$ = makeNode(DefElem);
- $$->defname = "security";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- | SECURITY INVOKER
- {
- $$ = makeNode(DefElem);
- $$->defname = "security";
- $$->arg = (Node *)makeInteger(FALSE);
- }
- | IMPLICIT CAST
- {
- $$ = makeNode(DefElem);
- $$->defname = "implicit";
- $$->arg = (Node *)makeInteger(TRUE);
- }
- ;
-
-func_as: Sconst { $$ = makeList1(makeString($1)); }
- | Sconst ',' Sconst
- {
- $$ = makeList2(makeString($1), makeString($3));
- }
- ;
-
-opt_definition:
- WITH definition { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- *
- * DROP FUNCTION funcname (arg1, arg2, ...)
- * DROP AGGREGATE aggname (aggtype)
- * DROP OPERATOR opname (leftoperand_typ rightoperand_typ)
- *
- *****************************************************************************/
-
-RemoveFuncStmt:
- DROP FUNCTION func_name func_args
- {
- RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
- n->funcname = $3;
- n->args = $4;
- $$ = (Node *)n;
- }
- ;
-
-RemoveAggrStmt:
- DROP AGGREGATE func_name '(' aggr_argtype ')'
- {
- RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
- n->aggname = $3;
- n->aggtype = $5;
- $$ = (Node *)n;
- }
- ;
-
-aggr_argtype:
- Typename { $$ = $1; }
- | '*' { $$ = NULL; }
- ;
-
-RemoveOperStmt:
- DROP OPERATOR any_operator '(' oper_argtypes ')'
- {
- RemoveOperStmt *n = makeNode(RemoveOperStmt);
- n->opname = $3;
- n->args = $5;
- $$ = (Node *)n;
- }
- ;
-
-oper_argtypes:
- Typename
- {
- elog(ERROR,"parser: argument type missing (use NONE for unary operators)");
- }
- | Typename ',' Typename
- { $$ = makeList2($1, $3); }
- | NONE ',' Typename /* left unary */
- { $$ = makeList2(NULL, $3); }
- | Typename ',' NONE /* right unary */
- { $$ = makeList2($1, NULL); }
- ;
-
-any_operator:
- all_Op
- { $$ = makeList1(makeString($1)); }
- | ColId '.' any_operator
- { $$ = lcons(makeString($1), $3); }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- *
- * REINDEX type <typename> [FORCE] [ALL]
- *
- *****************************************************************************/
-
-ReindexStmt:
- REINDEX reindex_type qualified_name opt_force
- {
- ReindexStmt *n = makeNode(ReindexStmt);
- n->reindexType = $2;
- n->relation = $3;
- n->name = NULL;
- n->force = $4;
- $$ = (Node *)n;
- }
- | REINDEX DATABASE name opt_force
- {
- ReindexStmt *n = makeNode(ReindexStmt);
- n->reindexType = DATABASE;
- n->name = $3;
- n->relation = NULL;
- n->force = $4;
- $$ = (Node *)n;
- }
- ;
-
-reindex_type:
- INDEX { $$ = INDEX; }
- | TABLE { $$ = TABLE; }
- ;
-
-opt_force: FORCE { $$ = TRUE; }
- | /* EMPTY */ { $$ = FALSE; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * rename <attrname1> in <relname> [*] to <attrname2>
- * rename <relname1> to <relname2>
- *
- *****************************************************************************/
-
-RenameStmt: ALTER TABLE relation_expr RENAME opt_column opt_name TO name
- {
- RenameStmt *n = makeNode(RenameStmt);
- n->relation = $3;
- n->oldname = $6;
- n->newname = $8;
- if ($6 == NULL)
- n->renameType = RENAME_TABLE;
- else
- n->renameType = RENAME_COLUMN;
- $$ = (Node *)n;
- }
- | ALTER TRIGGER name ON relation_expr RENAME TO name
- {
- RenameStmt *n = makeNode(RenameStmt);
- n->relation = $5;
- n->oldname = $3;
- n->newname = $8;
- n->renameType = RENAME_TRIGGER;
- $$ = (Node *)n;
- }
- ;
-
-opt_name: name { $$ = $1; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-opt_column: COLUMN { $$ = COLUMN; }
- | /*EMPTY*/ { $$ = 0; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY: Define Rewrite Rule
- *
- *****************************************************************************/
-
-RuleStmt: CREATE RULE name AS
- { QueryIsRule=TRUE; }
- ON event TO qualified_name where_clause
- DO opt_instead RuleActionList
- {
- RuleStmt *n = makeNode(RuleStmt);
- n->relation = $9;
- n->rulename = $3;
- n->whereClause = $10;
- n->event = $7;
- n->instead = $12;
- n->actions = $13;
- $$ = (Node *)n;
- QueryIsRule=FALSE;
- }
- ;
-
-RuleActionList:
- NOTHING { $$ = NIL; }
- | RuleActionStmt { $$ = makeList1($1); }
- | '(' RuleActionMulti ')' { $$ = $2; }
- ;
-
-/* the thrashing around here is to discard "empty" statements... */
-RuleActionMulti:
- RuleActionMulti ';' RuleActionStmtOrEmpty
- { if ($3 != (Node *) NULL)
- $$ = lappend($1, $3);
- else
- $$ = $1;
- }
- | RuleActionStmtOrEmpty
- { if ($1 != (Node *) NULL)
- $$ = makeList1($1);
- else
- $$ = NIL;
- }
- ;
-
-RuleActionStmt:
- SelectStmt
- | InsertStmt
- | UpdateStmt
- | DeleteStmt
- | NotifyStmt
- ;
-
-RuleActionStmtOrEmpty:
- RuleActionStmt { $$ = $1; }
- | /*EMPTY*/ { $$ = (Node *)NULL; }
- ;
-
-/* change me to select, update, etc. some day */
-event: SELECT { $$ = CMD_SELECT; }
- | UPDATE { $$ = CMD_UPDATE; }
- | DELETE_P { $$ = CMD_DELETE; }
- | INSERT { $$ = CMD_INSERT; }
- ;
-
-opt_instead:
- INSTEAD { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-
-DropRuleStmt:
- DROP RULE name ON qualified_name
- {
- DropPropertyStmt *n = makeNode(DropPropertyStmt);
- n->relation = $5;
- n->property = $3;
- n->removeType = DROP_RULE;
- $$ = (Node *) n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * NOTIFY <qualified_name> can appear both in rule bodies and
- * as a query-level command
- *
- *****************************************************************************/
-
-NotifyStmt: NOTIFY qualified_name
- {
- NotifyStmt *n = makeNode(NotifyStmt);
- n->relation = $2;
- $$ = (Node *)n;
- }
- ;
-
-ListenStmt: LISTEN qualified_name
- {
- ListenStmt *n = makeNode(ListenStmt);
- n->relation = $2;
- $$ = (Node *)n;
- }
- ;
-
-UnlistenStmt:
- UNLISTEN qualified_name
- {
- UnlistenStmt *n = makeNode(UnlistenStmt);
- n->relation = $2;
- $$ = (Node *)n;
- }
- | UNLISTEN '*'
- {
- UnlistenStmt *n = makeNode(UnlistenStmt);
- n->relation = makeNode(RangeVar);
- n->relation->relname = "*";
- n->relation->schemaname = NULL;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * Transactions:
- *
- * BEGIN / COMMIT / ROLLBACK
- * (also older versions END / ABORT)
- *
- *****************************************************************************/
-
-TransactionStmt:
- ABORT_TRANS opt_trans
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = ROLLBACK;
- $$ = (Node *)n;
- }
- | BEGIN_TRANS opt_trans
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = BEGIN_TRANS;
- $$ = (Node *)n;
- }
- | COMMIT opt_trans
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = COMMIT;
- $$ = (Node *)n;
- }
- | COMMIT opt_trans opt_chain
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = COMMIT;
- $$ = (Node *)n;
- }
- | END_TRANS opt_trans
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = COMMIT;
- $$ = (Node *)n;
- }
- | ROLLBACK opt_trans
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = ROLLBACK;
- $$ = (Node *)n;
- }
- | ROLLBACK opt_trans opt_chain
- {
- TransactionStmt *n = makeNode(TransactionStmt);
- n->command = ROLLBACK;
- $$ = (Node *)n;
- }
- ;
-
-opt_trans: WORK {}
- | TRANSACTION {}
- | /*EMPTY*/ {}
- ;
-
-opt_chain: AND NO CHAIN {}
- | AND CHAIN
- {
- /* SQL99 asks that conforming dbs reject AND CHAIN
- * if they don't support it. So we can't just ignore it.
- * - thomas 2000-08-06
- */
- elog(ERROR, "COMMIT / CHAIN not yet supported");
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * define view <viewname> '('target-list ')' [where <quals> ]
- *
- *****************************************************************************/
-
-ViewStmt: CREATE VIEW qualified_name opt_column_list AS SelectStmt
- {
- ViewStmt *n = makeNode(ViewStmt);
- n->view = $3;
- n->aliases = $4;
- n->query = (Query *) $6;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * load "filename"
- *
- *****************************************************************************/
-
-LoadStmt: LOAD file_name
- {
- LoadStmt *n = makeNode(LoadStmt);
- n->filename = $2;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * CREATE DATABASE
- *
- *****************************************************************************/
-
-CreatedbStmt:
- CREATE DATABASE database_name opt_with createdb_opt_list
- {
- CreatedbStmt *n = makeNode(CreatedbStmt);
- n->dbname = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
-
-createdb_opt_list:
- createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
-
-createdb_opt_item:
- LOCATION opt_equal Sconst
- {
- $$ = makeNode(DefElem);
- $$->defname = "location";
- $$->arg = (Node *)makeString($3);
- }
- | LOCATION opt_equal DEFAULT
- {
- $$ = makeNode(DefElem);
- $$->defname = "location";
- $$->arg = NULL;
- }
- | TEMPLATE opt_equal name
- {
- $$ = makeNode(DefElem);
- $$->defname = "template";
- $$->arg = (Node *)makeString($3);
- }
- | TEMPLATE opt_equal DEFAULT
- {
- $$ = makeNode(DefElem);
- $$->defname = "template";
- $$->arg = NULL;
- }
- | ENCODING opt_equal Sconst
- {
- int encoding;
-#ifdef MULTIBYTE
- encoding = pg_char_to_encoding($3);
- if (encoding == -1)
- elog(ERROR, "%s is not a valid encoding name", $3);
-#else
- if (strcasecmp($3, GetStandardEncodingName()) != 0)
- elog(ERROR, "Multi-byte support is not enabled");
- encoding = GetStandardEncoding();
-#endif
- $$ = makeNode(DefElem);
- $$->defname = "encoding";
- $$->arg = (Node *)makeInteger(encoding);
- }
- | ENCODING opt_equal Iconst
- {
-#ifdef MULTIBYTE
- if (!pg_get_enconv_by_encoding($3))
- elog(ERROR, "%d is not a valid encoding code", $3);
-#else
- if ($3 != GetStandardEncoding())
- elog(ERROR, "Multi-byte support is not enabled");
-#endif
- $$ = makeNode(DefElem);
- $$->defname = "encoding";
- $$->arg = (Node *)makeInteger($3);
- }
- | ENCODING opt_equal DEFAULT
- {
- $$ = makeNode(DefElem);
- $$->defname = "encoding";
- $$->arg = (Node *)makeInteger(-1);
- }
- | OWNER opt_equal name
- {
- $$ = makeNode(DefElem);
- $$->defname = "owner";
- $$->arg = (Node *)makeString($3);
- }
- | OWNER opt_equal DEFAULT
- {
- $$ = makeNode(DefElem);
- $$->defname = "owner";
- $$->arg = NULL;
- }
- ;
-
-/*
- * Though the equals sign doesn't match other WITH options, pg_dump uses
- * equals for backward compability, and it doesn't seem worth removing it.
- * 2002-02-25
- */
-opt_equal: '=' {}
- | /*EMPTY*/ {}
- ;
-
-
-/*****************************************************************************
- *
- * ALTER DATABASE
- *
- *****************************************************************************/
-
-AlterDatabaseSetStmt:
- ALTER DATABASE database_name SET set_rest
- {
- AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
- n->dbname = $3;
- n->variable = $5->name;
- n->value = $5->args;
- $$ = (Node *)n;
- }
- | ALTER DATABASE database_name VariableResetStmt
- {
- AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
- n->dbname = $3;
- n->variable = ((VariableResetStmt *)$4)->name;
- n->value = NIL;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * DROP DATABASE
- *
- *****************************************************************************/
-
-DropdbStmt: DROP DATABASE database_name
- {
- DropdbStmt *n = makeNode(DropdbStmt);
- n->dbname = $3;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * Manipulate a domain
- *
- *****************************************************************************/
-
-CreateDomainStmt:
- CREATE DOMAIN_P any_name opt_as Typename ColQualList opt_collate
- {
- CreateDomainStmt *n = makeNode(CreateDomainStmt);
- n->domainname = $3;
- n->typename = $5;
- n->constraints = $6;
-
- if ($7 != NULL)
- elog(NOTICE,"CREATE DOMAIN / COLLATE %s not yet "
- "implemented; clause ignored", $7);
- $$ = (Node *)n;
- }
- ;
-
-opt_as: AS {}
- | /* EMPTY */ {}
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * cluster <index_name> on <qualified_name>
- *
- *****************************************************************************/
-
-ClusterStmt:
- CLUSTER index_name ON qualified_name
- {
- ClusterStmt *n = makeNode(ClusterStmt);
- n->relation = $4;
- n->indexname = $2;
- $$ = (Node*)n;
- }
- ;
-
-/*****************************************************************************
- *
- * QUERY:
- * vacuum
- * analyze
- *
- *****************************************************************************/
-
-VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
- {
- VacuumStmt *n = makeNode(VacuumStmt);
- n->vacuum = true;
- n->analyze = false;
- n->full = $2;
- n->freeze = $3;
- n->verbose = $4;
- n->relation = NULL;
- n->va_cols = NIL;
- $$ = (Node *)n;
- }
- | VACUUM opt_full opt_freeze opt_verbose qualified_name
- {
- VacuumStmt *n = makeNode(VacuumStmt);
- n->vacuum = true;
- n->analyze = false;
- n->full = $2;
- n->freeze = $3;
- n->verbose = $4;
- n->relation = $5;
- n->va_cols = NIL;
- $$ = (Node *)n;
- }
- | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
- {
- VacuumStmt *n = (VacuumStmt *) $5;
- n->vacuum = true;
- n->full = $2;
- n->freeze = $3;
- n->verbose |= $4;
- $$ = (Node *)n;
- }
- ;
-
-AnalyzeStmt:
- analyze_keyword opt_verbose
- {
- VacuumStmt *n = makeNode(VacuumStmt);
- n->vacuum = false;
- n->analyze = true;
- n->full = false;
- n->freeze = false;
- n->verbose = $2;
- n->relation = NULL;
- n->va_cols = NIL;
- $$ = (Node *)n;
- }
- | analyze_keyword opt_verbose qualified_name opt_name_list
- {
- VacuumStmt *n = makeNode(VacuumStmt);
- n->vacuum = false;
- n->analyze = true;
- n->full = false;
- n->freeze = false;
- n->verbose = $2;
- n->relation = $3;
- n->va_cols = $4;
- $$ = (Node *)n;
- }
- ;
-
-analyze_keyword:
- ANALYZE {}
- | ANALYSE /* British */ {}
- ;
-
-opt_verbose:
- VERBOSE { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-opt_full: FULL { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-opt_freeze: FREEZE { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-opt_name_list:
- '(' name_list ')' { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * EXPLAIN query
- * EXPLAIN ANALYZE query
- *
- *****************************************************************************/
-
-ExplainStmt:
- EXPLAIN opt_verbose OptimizableStmt
- {
- ExplainStmt *n = makeNode(ExplainStmt);
- n->verbose = $2;
- n->analyze = FALSE;
- n->query = (Query*)$3;
- $$ = (Node *)n;
- }
- | EXPLAIN analyze_keyword opt_verbose OptimizableStmt
- {
- ExplainStmt *n = makeNode(ExplainStmt);
- n->verbose = $3;
- n->analyze = TRUE;
- n->query = (Query*)$4;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- * *
- * Optimizable Stmts: *
- * *
- * one of the five queries processed by the planner *
- * *
- * [ultimately] produces query-trees as specified *
- * in the query-spec document in ~postgres/ref *
- * *
- *****************************************************************************/
-
-OptimizableStmt:
- SelectStmt
- | CursorStmt
- | UpdateStmt
- | InsertStmt
- | DeleteStmt /* by default all are $$=$1 */
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * INSERT STATEMENTS
- *
- *****************************************************************************/
-
-InsertStmt:
- INSERT INTO qualified_name insert_rest
- {
- $4->relation = $3;
- $$ = (Node *) $4;
- }
- ;
-
-insert_rest:
- VALUES '(' insert_target_list ')'
- {
- $$ = makeNode(InsertStmt);
- $$->cols = NIL;
- $$->targetList = $3;
- $$->selectStmt = NULL;
- }
- | DEFAULT VALUES
- {
- $$ = makeNode(InsertStmt);
- $$->cols = NIL;
- $$->targetList = NIL;
- $$->selectStmt = NULL;
- }
- | SelectStmt
- {
- $$ = makeNode(InsertStmt);
- $$->cols = NIL;
- $$->targetList = NIL;
- $$->selectStmt = $1;
- }
- | '(' insert_column_list ')' VALUES '(' insert_target_list ')'
- {
- $$ = makeNode(InsertStmt);
- $$->cols = $2;
- $$->targetList = $6;
- $$->selectStmt = NULL;
- }
- | '(' insert_column_list ')' SelectStmt
- {
- $$ = makeNode(InsertStmt);
- $$->cols = $2;
- $$->targetList = NIL;
- $$->selectStmt = $4;
- }
- ;
-
-insert_column_list:
- insert_column_item { $$ = makeList1($1); }
- | insert_column_list ',' insert_column_item
- { $$ = lappend($1, $3); }
- ;
-
-insert_column_item:
- ColId opt_indirection
- {
- ResTarget *n = makeNode(ResTarget);
- n->name = $1;
- n->indirection = $2;
- n->val = NULL;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * DELETE STATEMENTS
- *
- *****************************************************************************/
-
-DeleteStmt: DELETE_P FROM relation_expr where_clause
- {
- DeleteStmt *n = makeNode(DeleteStmt);
- n->relation = $3;
- n->whereClause = $4;
- $$ = (Node *)n;
- }
- ;
-
-LockStmt: LOCK_P opt_table qualified_name_list opt_lock
- {
- LockStmt *n = makeNode(LockStmt);
-
- n->relations = $3;
- n->mode = $4;
- $$ = (Node *)n;
- }
- ;
-
-opt_lock: IN_P lock_type MODE { $$ = $2; }
- | /*EMPTY*/ { $$ = AccessExclusiveLock; }
- ;
-
-lock_type: ACCESS SHARE { $$ = AccessShareLock; }
- | ROW SHARE { $$ = RowShareLock; }
- | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
- | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
- | SHARE { $$ = ShareLock; }
- | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
- | EXCLUSIVE { $$ = ExclusiveLock; }
- | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * UpdateStmt (UPDATE)
- *
- *****************************************************************************/
-
-UpdateStmt: UPDATE relation_expr
- SET update_target_list
- from_clause
- where_clause
- {
- UpdateStmt *n = makeNode(UpdateStmt);
- n->relation = $2;
- n->targetList = $4;
- n->fromClause = $5;
- n->whereClause = $6;
- $$ = (Node *)n;
- }
- ;
-
-
-/*****************************************************************************
- *
- * QUERY:
- * CURSOR STATEMENTS
- *
- *****************************************************************************/
-CursorStmt: DECLARE name opt_cursor CURSOR FOR SelectStmt
- {
- SelectStmt *n = (SelectStmt *)$6;
- n->portalname = $2;
- n->binary = $3;
- $$ = $6;
- }
- ;
-
-opt_cursor: BINARY { $$ = TRUE; }
- | INSENSITIVE { $$ = FALSE; }
- | SCROLL { $$ = FALSE; }
- | INSENSITIVE SCROLL { $$ = FALSE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-/*****************************************************************************
- *
- * QUERY:
- * SELECT STATEMENTS
- *
- *****************************************************************************/
-
-/* A complete SELECT statement looks like this.
- *
- * The rule returns either a single SelectStmt node or a tree of them,
- * representing a set-operation tree.
- *
- * There is an ambiguity when a sub-SELECT is within an a_expr and there
- * are excess parentheses: do the parentheses belong to the sub-SELECT or
- * to the surrounding a_expr? We don't really care, but yacc wants to know.
- * To resolve the ambiguity, we are careful to define the grammar so that
- * the decision is staved off as long as possible: as long as we can keep
- * absorbing parentheses into the sub-SELECT, we will do so, and only when
- * it's no longer possible to do that will we decide that parens belong to
- * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
- * parentheses are treated as part of the sub-select. The necessity of doing
- * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
- * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
- * SELECT viewpoint when we see the UNION.
- *
- * This approach is implemented by defining a nonterminal select_with_parens,
- * which represents a SELECT with at least one outer layer of parentheses,
- * and being careful to use select_with_parens, never '(' SelectStmt ')',
- * in the expression grammar. We will then have shift-reduce conflicts
- * which we can resolve in favor of always treating '(' <select> ')' as
- * a select_with_parens. To resolve the conflicts, the productions that
- * conflict with the select_with_parens productions are manually given
- * precedences lower than the precedence of ')', thereby ensuring that we
- * shift ')' (and then reduce to select_with_parens) rather than trying to
- * reduce the inner <select> nonterminal to something else. We use UMINUS
- * precedence for this, which is a fairly arbitrary choice.
- *
- * To be able to define select_with_parens itself without ambiguity, we need
- * a nonterminal select_no_parens that represents a SELECT structure with no
- * outermost parentheses. This is a little bit tedious, but it works.
- *
- * In non-expression contexts, we use SelectStmt which can represent a SELECT
- * with or without outer parentheses.
- */
-
-SelectStmt: select_no_parens %prec UMINUS
- | select_with_parens %prec UMINUS
- ;
-
-select_with_parens:
- '(' select_no_parens ')' { $$ = $2; }
- | '(' select_with_parens ')' { $$ = $2; }
- ;
-
-select_no_parens:
- simple_select { $$ = $1; }
- | select_clause sort_clause opt_for_update_clause opt_select_limit
- {
- insertSelectOptions((SelectStmt *) $1, $2, $3,
- nth(0, $4), nth(1, $4));
- $$ = $1;
- }
- | select_clause for_update_clause opt_select_limit
- {
- insertSelectOptions((SelectStmt *) $1, NIL, $2,
- nth(0, $3), nth(1, $3));
- $$ = $1;
- }
- | select_clause select_limit
- {
- insertSelectOptions((SelectStmt *) $1, NIL, NIL,
- nth(0, $2), nth(1, $2));
- $$ = $1;
- }
- ;
-
-select_clause:
- simple_select { $$ = $1; }
- | select_with_parens { $$ = $1; }
- ;
-
-/*
- * This rule parses SELECT statements that can appear within set operations,
- * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
- * the ordering of the set operations. Without '(' and ')' we want the
- * operations to be ordered per the precedence specs at the head of this file.
- *
- * As with select_no_parens, simple_select cannot have outer parentheses,
- * but can have parenthesized subclauses.
- *
- * Note that sort clauses cannot be included at this level --- SQL92 requires
- * SELECT foo UNION SELECT bar ORDER BY baz
- * to be parsed as
- * (SELECT foo UNION SELECT bar) ORDER BY baz
- * not
- * SELECT foo UNION (SELECT bar ORDER BY baz)
- * Likewise FOR UPDATE and LIMIT. Therefore, those clauses are described
- * as part of the select_no_parens production, not simple_select.
- * This does not limit functionality, because you can reintroduce sort and
- * limit clauses inside parentheses.
- *
- * NOTE: only the leftmost component SelectStmt should have INTO.
- * However, this is not checked by the grammar; parse analysis must check it.
- */
-simple_select:
- SELECT opt_distinct target_list
- into_clause from_clause where_clause
- group_clause having_clause
- {
- SelectStmt *n = makeNode(SelectStmt);
- n->distinctClause = $2;
- n->targetList = $3;
- n->into = $4;
- n->intoColNames = NIL;
- n->fromClause = $5;
- n->whereClause = $6;
- n->groupClause = $7;
- n->havingClause = $8;
- $$ = (Node *)n;
- }
- | select_clause UNION opt_all select_clause
- {
- $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
- }
- | select_clause INTERSECT opt_all select_clause
- {
- $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
- }
- | select_clause EXCEPT opt_all select_clause
- {
- $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
- }
- ;
-
-into_clause:
- INTO OptTempTableName { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-/*
- * Redundancy here is needed to avoid shift/reduce conflicts,
- * since TEMP is not a reserved word. See also OptTemp.
- */
-OptTempTableName:
- TEMPORARY opt_table qualified_name
- {
- $$ = $3;
- $$->istemp = true;
- }
- | TEMP opt_table qualified_name
- {
- $$ = $3;
- $$->istemp = true;
- }
- | LOCAL TEMPORARY opt_table qualified_name
- {
- $$ = $4;
- $$->istemp = true;
- }
- | LOCAL TEMP opt_table qualified_name
- {
- $$ = $4;
- $$->istemp = true;
- }
- | GLOBAL TEMPORARY opt_table qualified_name
- {
- elog(ERROR,
- "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = $4;
- $$->istemp = true;
- }
- | GLOBAL TEMP opt_table qualified_name
- {
- elog(ERROR,
- "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = $4;
- $$->istemp = true;
- }
- | TABLE qualified_name
- {
- $$ = $2;
- $$->istemp = false;
- }
- | qualified_name
- {
- $$ = $1;
- $$->istemp = false;
- }
- ;
-
-opt_table: TABLE {}
- | /*EMPTY*/ {}
- ;
-
-opt_all: ALL { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-/* We use (NIL) as a placeholder to indicate that all target expressions
- * should be placed in the DISTINCT list during parsetree analysis.
- */
-opt_distinct:
- DISTINCT { $$ = makeList1(NIL); }
- | DISTINCT ON '(' expr_list ')' { $$ = $4; }
- | ALL { $$ = NIL; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-sort_clause:
- ORDER BY sortby_list { $$ = $3; }
- ;
-
-sortby_list:
- sortby { $$ = makeList1($1); }
- | sortby_list ',' sortby { $$ = lappend($1, $3); }
- ;
-
-sortby: a_expr OptUseOp
- {
- $$ = makeNode(SortGroupBy);
- $$->node = $1;
- $$->useOp = $2;
- }
- ;
-
-OptUseOp: USING qual_all_Op { $$ = $2; }
- | ASC
- { $$ = makeList1(makeString("<")); }
- | DESC
- { $$ = makeList1(makeString(">")); }
- | /*EMPTY*/
- { $$ = makeList1(makeString("<")); /*default*/ }
- ;
-
-
-select_limit:
- LIMIT select_limit_value OFFSET select_offset_value
- { $$ = makeList2($4, $2); }
- | OFFSET select_offset_value LIMIT select_limit_value
- { $$ = makeList2($2, $4); }
- | LIMIT select_limit_value
- { $$ = makeList2(NULL, $2); }
- | OFFSET select_offset_value
- { $$ = makeList2($2, NULL); }
- | LIMIT select_limit_value ',' select_offset_value
- /* Disabled because it was too confusing, bjm 2002-02-18 */
- { elog(ERROR,
- "LIMIT #,# syntax not supported.\n\tUse separate LIMIT and OFFSET clauses."); }
- ;
-
-
-opt_select_limit:
- select_limit { $$ = $1; }
- | /* EMPTY */
- { $$ = makeList2(NULL,NULL); }
- ;
-
-select_limit_value:
- Iconst
- {
- Const *n = makeNode(Const);
-
- if ($1 < 0)
- elog(ERROR, "LIMIT must not be negative");
-
- n->consttype = INT4OID;
- n->constlen = sizeof(int4);
- n->constvalue = Int32GetDatum($1);
- n->constisnull = FALSE;
- n->constbyval = TRUE;
- n->constisset = FALSE;
- n->constiscast = FALSE;
- $$ = (Node *)n;
- }
- | ALL
- {
- /* LIMIT ALL is represented as a NULL constant */
- Const *n = makeNode(Const);
-
- n->consttype = INT4OID;
- n->constlen = sizeof(int4);
- n->constvalue = (Datum) 0;
- n->constisnull = TRUE;
- n->constbyval = TRUE;
- n->constisset = FALSE;
- n->constiscast = FALSE;
- $$ = (Node *)n;
- }
- | PARAM
- {
- Param *n = makeNode(Param);
-
- n->paramkind = PARAM_NUM;
- n->paramid = $1;
- n->paramtype = INT4OID;
- $$ = (Node *)n;
- }
- ;
-
-select_offset_value:
- Iconst
- {
- Const *n = makeNode(Const);
-
- if ($1 < 0)
- elog(ERROR, "OFFSET must not be negative");
-
- n->consttype = INT4OID;
- n->constlen = sizeof(int4);
- n->constvalue = Int32GetDatum($1);
- n->constisnull = FALSE;
- n->constbyval = TRUE;
- n->constisset = FALSE;
- n->constiscast = FALSE;
- $$ = (Node *)n;
- }
- | PARAM
- {
- Param *n = makeNode(Param);
-
- n->paramkind = PARAM_NUM;
- n->paramid = $1;
- n->paramtype = INT4OID;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * jimmy bell-style recursive queries aren't supported in the
- * current system.
- *
- * ...however, recursive addattr and rename supported. make special
- * cases for these.
- */
-
-group_clause:
- GROUP_P BY expr_list { $$ = $3; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-having_clause:
- HAVING a_expr { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-for_update_clause:
- FOR UPDATE update_list { $$ = $3; }
- | FOR READ ONLY { $$ = NULL; }
- ;
-
-opt_for_update_clause:
- for_update_clause { $$ = $1; }
- | /* EMPTY */ { $$ = NULL; }
- ;
-
-update_list:
- OF name_list { $$ = $2; }
- | /* EMPTY */ { $$ = makeList1(NULL); }
- ;
-
-/*****************************************************************************
- *
- * clauses common to all Optimizable Stmts:
- * from_clause - allow list of both JOIN expressions and table names
- * where_clause - qualifications for joins or restrictions
- *
- *****************************************************************************/
-
-from_clause:
- FROM from_list { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-from_list:
- table_ref { $$ = makeList1($1); }
- | from_list ',' table_ref { $$ = lappend($1, $3); }
- ;
-
-/*
- * table_ref is where an alias clause can be attached. Note we cannot make
- * alias_clause have an empty production because that causes parse conflicts
- * between table_ref := '(' joined_table ')' alias_clause
- * and joined_table := '(' joined_table ')'. So, we must have the
- * redundant-looking productions here instead.
- */
-table_ref: relation_expr
- {
- $$ = (Node *) $1;
- }
- | relation_expr alias_clause
- {
- $1->alias = $2;
- $$ = (Node *) $1;
- }
- | func_table
- {
- RangeFunction *n = makeNode(RangeFunction);
- n->funccallnode = $1;
- $$ = (Node *) n;
- }
- | func_table alias_clause
- {
- RangeFunction *n = makeNode(RangeFunction);
- n->funccallnode = $1;
- n->alias = $2;
- $$ = (Node *) n;
- }
- | select_with_parens
- {
- /*
- * The SQL spec does not permit a subselect
- * (<derived_table>) without an alias clause,
- * so we don't either. This avoids the problem
- * of needing to invent a unique refname for it.
- * That could be surmounted if there's sufficient
- * popular demand, but for now let's just implement
- * the spec and see if anyone complains.
- * However, it does seem like a good idea to emit
- * an error message that's better than "parse error".
- */
- elog(ERROR, "sub-SELECT in FROM must have an alias"
- "\n\tFor example, FROM (SELECT ...) [AS] foo");
- $$ = NULL;
- }
- | select_with_parens alias_clause
- {
- RangeSubselect *n = makeNode(RangeSubselect);
- n->subquery = $1;
- n->alias = $2;
- $$ = (Node *) n;
- }
- | joined_table
- {
- $$ = (Node *) $1;
- }
- | '(' joined_table ')' alias_clause
- {
- $2->alias = $4;
- $$ = (Node *) $2;
- }
- ;
-
-
-/*
- * It may seem silly to separate joined_table from table_ref, but there is
- * method in SQL92's madness: if you don't do it this way you get reduce-
- * reduce conflicts, because it's not clear to the parser generator whether
- * to expect alias_clause after ')' or not. For the same reason we must
- * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
- * join_type to expand to empty; if we try it, the parser generator can't
- * figure out when to reduce an empty join_type right after table_ref.
- *
- * Note that a CROSS JOIN is the same as an unqualified
- * INNER JOIN, and an INNER JOIN/ON has the same shape
- * but a qualification expression to limit membership.
- * A NATURAL JOIN implicitly matches column names between
- * tables and the shape is determined by which columns are
- * in common. We'll collect columns during the later transformations.
- */
-
-joined_table:
- '(' joined_table ')'
- {
- $$ = $2;
- }
- | table_ref CROSS JOIN table_ref
- {
- /* CROSS JOIN is same as unqualified inner join */
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = JOIN_INNER;
- n->isNatural = FALSE;
- n->larg = $1;
- n->rarg = $4;
- n->using = NIL;
- n->quals = NULL;
- $$ = n;
- }
- | table_ref UNIONJOIN table_ref
- {
- /* UNION JOIN is made into 1 token to avoid shift/reduce
- * conflict against regular UNION keyword.
- */
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = JOIN_UNION;
- n->isNatural = FALSE;
- n->larg = $1;
- n->rarg = $3;
- n->using = NIL;
- n->quals = NULL;
- $$ = n;
- }
- | table_ref join_type JOIN table_ref join_qual
- {
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = $2;
- n->isNatural = FALSE;
- n->larg = $1;
- n->rarg = $4;
- if ($5 != NULL && IsA($5, List))
- n->using = (List *) $5; /* USING clause */
- else
- n->quals = $5; /* ON clause */
- $$ = n;
- }
- | table_ref JOIN table_ref join_qual
- {
- /* letting join_type reduce to empty doesn't work */
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = JOIN_INNER;
- n->isNatural = FALSE;
- n->larg = $1;
- n->rarg = $3;
- if ($4 != NULL && IsA($4, List))
- n->using = (List *) $4; /* USING clause */
- else
- n->quals = $4; /* ON clause */
- $$ = n;
- }
- | table_ref NATURAL join_type JOIN table_ref
- {
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = $3;
- n->isNatural = TRUE;
- n->larg = $1;
- n->rarg = $5;
- n->using = NIL; /* figure out which columns later... */
- n->quals = NULL; /* fill later */
- $$ = n;
- }
- | table_ref NATURAL JOIN table_ref
- {
- /* letting join_type reduce to empty doesn't work */
- JoinExpr *n = makeNode(JoinExpr);
- n->jointype = JOIN_INNER;
- n->isNatural = TRUE;
- n->larg = $1;
- n->rarg = $4;
- n->using = NIL; /* figure out which columns later... */
- n->quals = NULL; /* fill later */
- $$ = n;
- }
- ;
-
-alias_clause:
- AS ColId '(' name_list ')'
- {
- $$ = makeNode(Alias);
- $$->aliasname = $2;
- $$->colnames = $4;
- }
- | AS ColId
- {
- $$ = makeNode(Alias);
- $$->aliasname = $2;
- }
- | ColId '(' name_list ')'
- {
- $$ = makeNode(Alias);
- $$->aliasname = $1;
- $$->colnames = $3;
- }
- | ColId
- {
- $$ = makeNode(Alias);
- $$->aliasname = $1;
- }
- ;
-
-join_type: FULL join_outer { $$ = JOIN_FULL; }
- | LEFT join_outer { $$ = JOIN_LEFT; }
- | RIGHT join_outer { $$ = JOIN_RIGHT; }
- | INNER_P { $$ = JOIN_INNER; }
- ;
-
-/* OUTER is just noise... */
-join_outer: OUTER_P { $$ = NULL; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-/* JOIN qualification clauses
- * Possibilities are:
- * USING ( column list ) allows only unqualified column names,
- * which must match between tables.
- * ON expr allows more general qualifications.
- *
- * We return USING as a List node, while an ON-expr will not be a List.
- */
-
-join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
- | ON a_expr { $$ = $2; }
- ;
-
-
-relation_expr:
- qualified_name
- {
- /* default inheritance */
- $$ = $1;
- $$->inhOpt = INH_DEFAULT;
- $$->alias = NULL;
- }
- | qualified_name '*'
- {
- /* inheritance query */
- $$ = $1;
- $$->inhOpt = INH_YES;
- $$->alias = NULL;
- }
- | ONLY qualified_name
- {
- /* no inheritance */
- $$ = $2;
- $$->inhOpt = INH_NO;
- $$->alias = NULL;
- }
- ;
-
-
-func_table: func_name '(' ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = NIL;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | func_name '(' expr_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- ;
-
-
-where_clause:
- WHERE a_expr { $$ = $2; }
- /* no qualifiers */
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-
-/*****************************************************************************
- *
- * Type syntax
- * SQL92 introduces a large amount of type-specific syntax.
- * Define individual clauses to handle these cases, and use
- * the generic case to handle regular type-extensible Postgres syntax.
- * - thomas 1997-10-10
- *
- *****************************************************************************/
-
-Typename: SimpleTypename opt_array_bounds
- {
- $$ = $1;
- $$->arrayBounds = $2;
- }
- | SETOF SimpleTypename
- {
- $$ = $2;
- $$->setof = TRUE;
- }
- ;
-
-opt_array_bounds:
- opt_array_bounds '[' ']'
- { $$ = lappend($1, makeInteger(-1)); }
- | opt_array_bounds '[' Iconst ']'
- { $$ = lappend($1, makeInteger($3)); }
- | /*EMPTY*/
- { $$ = NIL; }
- ;
-
-/*
- * XXX ideally, the production for a qualified typename should be ColId attrs
- * (there's no obvious reason why the first name should need to be restricted)
- * and should be an alternative of GenericType (so that it can be used to
- * specify a type for a literal in AExprConst). However doing either causes
- * reduce/reduce conflicts that I haven't been able to find a workaround
- * for. FIXME later.
- */
-SimpleTypename:
- ConstTypename { $$ = $1; }
- | ConstInterval opt_interval
- {
- $$ = $1;
- if ($2 != -1)
- $$->typmod = ((($2 & 0x7FFF) << 16) | 0xFFFF);
- }
- | ConstInterval '(' Iconst ')' opt_interval
- {
- $$ = $1;
- if (($3 < 0) || ($3 > MAX_INTERVAL_PRECISION))
- elog(ERROR,
- "INTERVAL(%d) precision must be between %d and %d",
- $3, 0, MAX_INTERVAL_PRECISION);
- $$->typmod = ((($5 & 0x7FFF) << 16) | $3);
- }
- | type_name attrs
- {
- $$ = makeNode(TypeName);
- $$->names = lcons(makeString($1), $2);
- $$->typmod = -1;
- }
- ;
-
-ConstTypename:
- GenericType { $$ = $1;}
- | Numeric { $$ = $1;}
- | Bit { $$ = $1;}
- | Character { $$ = $1;}
- | ConstDatetime { $$ = $1;}
- ;
-
-GenericType:
- type_name
- {
- $$ = makeTypeName($1);
- }
- ;
-
-/* SQL92 numeric data types
- * Check FLOAT() precision limits assuming IEEE floating types.
- * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
- * - thomas 1997-09-18
- */
-Numeric: INT
- {
- $$ = SystemTypeName("int4");
- }
- | INTEGER
- {
- $$ = SystemTypeName("int4");
- }
- | SMALLINT
- {
- $$ = SystemTypeName("int2");
- }
- | BIGINT
- {
- $$ = SystemTypeName("int8");
- }
- | REAL
- {
- $$ = SystemTypeName("float4");
- }
- | FLOAT_P opt_float
- {
- $$ = $2;
- }
- | DOUBLE PRECISION
- {
- $$ = SystemTypeName("float8");
- }
- | DECIMAL opt_decimal
- {
- $$ = SystemTypeName("numeric");
- $$->typmod = $2;
- }
- | DEC opt_decimal
- {
- $$ = SystemTypeName("numeric");
- $$->typmod = $2;
- }
- | NUMERIC opt_numeric
- {
- $$ = SystemTypeName("numeric");
- $$->typmod = $2;
- }
- | BOOLEAN
- {
- $$ = SystemTypeName("bool");
- }
- ;
-
-opt_float: '(' Iconst ')'
- {
- if ($2 < 1)
- elog(ERROR,
- "precision for FLOAT must be at least 1");
- else if ($2 < 7)
- $$ = SystemTypeName("float4");
- else if ($2 < 16)
- $$ = SystemTypeName("float8");
- else
- elog(ERROR,
- "precision for FLOAT must be less than 16");
- }
- | /*EMPTY*/
- {
- $$ = SystemTypeName("float8");
- }
- ;
-
-opt_numeric:
- '(' Iconst ',' Iconst ')'
- {
- if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
- elog(ERROR,
- "NUMERIC precision %d must be between 1 and %d",
- $2, NUMERIC_MAX_PRECISION);
- if ($4 < 0 || $4 > $2)
- elog(ERROR,
- "NUMERIC scale %d must be between 0 and precision %d",
- $4,$2);
-
- $$ = (($2 << 16) | $4) + VARHDRSZ;
- }
- | '(' Iconst ')'
- {
- if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
- elog(ERROR,
- "NUMERIC precision %d must be between 1 and %d",
- $2, NUMERIC_MAX_PRECISION);
-
- $$ = ($2 << 16) + VARHDRSZ;
- }
- | /*EMPTY*/
- {
- /* Insert "-1" meaning "no limit" */
- $$ = -1;
- }
- ;
-
-opt_decimal:
- '(' Iconst ',' Iconst ')'
- {
- if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
- elog(ERROR,
- "DECIMAL precision %d must be between 1 and %d",
- $2, NUMERIC_MAX_PRECISION);
- if ($4 < 0 || $4 > $2)
- elog(ERROR,
- "DECIMAL scale %d must be between 0 and precision %d",
- $4,$2);
-
- $$ = (($2 << 16) | $4) + VARHDRSZ;
- }
- | '(' Iconst ')'
- {
- if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
- elog(ERROR,
- "DECIMAL precision %d must be between 1 and %d",
- $2, NUMERIC_MAX_PRECISION);
-
- $$ = ($2 << 16) + VARHDRSZ;
- }
- | /*EMPTY*/
- {
- /* Insert "-1" meaning "no limit" */
- $$ = -1;
- }
- ;
-
-
-/*
- * SQL92 bit-field data types
- * The following implements BIT() and BIT VARYING().
- */
-Bit: BIT opt_varying '(' Iconst ')'
- {
- char *typname;
-
- typname = $2 ? "varbit" : "bit";
- $$ = SystemTypeName(typname);
- if ($4 < 1)
- elog(ERROR, "length for type '%s' must be at least 1",
- typname);
- else if ($4 > (MaxAttrSize * BITS_PER_BYTE))
- elog(ERROR, "length for type '%s' cannot exceed %d",
- typname, (MaxAttrSize * BITS_PER_BYTE));
- $$->typmod = $4;
- }
- | BIT opt_varying
- {
- /* bit defaults to bit(1), varbit to no limit */
- if ($2)
- {
- $$ = SystemTypeName("varbit");
- $$->typmod = -1;
- }
- else
- {
- $$ = SystemTypeName("bit");
- $$->typmod = 1;
- }
- }
- ;
-
-
-/*
- * SQL92 character data types
- * The following implements CHAR() and VARCHAR().
- */
-Character: character '(' Iconst ')' opt_charset
- {
- if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
- {
- char *type;
-
- type = palloc(strlen($1) + 1 + strlen($5) + 1);
- strcpy(type, $1);
- strcat(type, "_");
- strcat(type, $5);
- $1 = type;
- }
-
- $$ = SystemTypeName($1);
-
- if ($3 < 1)
- elog(ERROR, "length for type '%s' must be at least 1",
- $1);
- else if ($3 > MaxAttrSize)
- elog(ERROR, "length for type '%s' cannot exceed %d",
- $1, MaxAttrSize);
-
- /* we actually implement these like a varlen, so
- * the first 4 bytes is the length. (the difference
- * between these and "text" is that we blank-pad and
- * truncate where necessary)
- */
- $$->typmod = VARHDRSZ + $3;
- }
- | character opt_charset
- {
- if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
- {
- char *type;
-
- type = palloc(strlen($1) + 1 + strlen($2) + 1);
- strcpy(type, $1);
- strcat(type, "_");
- strcat(type, $2);
- $1 = type;
- }
-
- $$ = SystemTypeName($1);
-
- /* char defaults to char(1), varchar to no limit */
- if (strcmp($1, "bpchar") == 0)
- $$->typmod = VARHDRSZ + 1;
- else
- $$->typmod = -1;
- }
- ;
-
-character: CHARACTER opt_varying
- { $$ = $2 ? "varchar": "bpchar"; }
- | CHAR_P opt_varying
- { $$ = $2 ? "varchar": "bpchar"; }
- | VARCHAR
- { $$ = "varchar"; }
- | NATIONAL CHARACTER opt_varying
- { $$ = $3 ? "varchar": "bpchar"; }
- | NATIONAL CHAR_P opt_varying
- { $$ = $3 ? "varchar": "bpchar"; }
- | NCHAR opt_varying
- { $$ = $2 ? "varchar": "bpchar"; }
- ;
-
-opt_varying:
- VARYING { $$ = TRUE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-opt_charset:
- CHARACTER SET ColId { $$ = $3; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-opt_collate:
- COLLATE ColId { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-ConstDatetime:
- TIMESTAMP '(' Iconst ')' opt_timezone
- {
- if ($5)
- $$ = SystemTypeName("timestamptz");
- else
- $$ = SystemTypeName("timestamp");
- /* XXX the timezone field seems to be unused
- * - thomas 2001-09-06
- */
- $$->timezone = $5;
- if (($3 < 0) || ($3 > MAX_TIMESTAMP_PRECISION))
- elog(ERROR,
- "TIMESTAMP(%d)%s precision must be between %d and %d",
- $3, ($5 ? " WITH TIME ZONE": ""), 0,
- MAX_TIMESTAMP_PRECISION);
- $$->typmod = $3;
- }
- | TIMESTAMP opt_timezone
- {
- if ($2)
- $$ = SystemTypeName("timestamptz");
- else
- $$ = SystemTypeName("timestamp");
- /* XXX the timezone field seems to be unused
- * - thomas 2001-09-06
- */
- $$->timezone = $2;
- /* SQL99 specified a default precision of six
- * for schema definitions. But for timestamp
- * literals we don't want to throw away precision
- * so leave this as unspecified for now.
- * Later, we may want a different production
- * for schemas. - thomas 2001-12-07
- */
- $$->typmod = -1;
- }
- | TIME '(' Iconst ')' opt_timezone
- {
- if ($5)
- $$ = SystemTypeName("timetz");
- else
- $$ = SystemTypeName("time");
- if (($3 < 0) || ($3 > MAX_TIME_PRECISION))
- elog(ERROR,
- "TIME(%d)%s precision must be between %d and %d",
- $3, ($5 ? " WITH TIME ZONE": ""), 0,
- MAX_TIME_PRECISION);
- $$->typmod = $3;
- }
- | TIME opt_timezone
- {
- if ($2)
- $$ = SystemTypeName("timetz");
- else
- $$ = SystemTypeName("time");
- /* SQL99 specified a default precision of zero.
- * See comments for timestamp above on why we will
- * leave this unspecified for now. - thomas 2001-12-07
- */
- $$->typmod = -1;
- }
- ;
-
-ConstInterval:
- INTERVAL { $$ = SystemTypeName("interval"); }
- ;
-
-opt_timezone:
- WITH TIME ZONE { $$ = TRUE; }
- | WITHOUT TIME ZONE { $$ = FALSE; }
- | /*EMPTY*/ { $$ = FALSE; }
- ;
-
-opt_interval:
- YEAR_P { $$ = MASK(YEAR); }
- | MONTH_P { $$ = MASK(MONTH); }
- | DAY_P { $$ = MASK(DAY); }
- | HOUR_P { $$ = MASK(HOUR); }
- | MINUTE_P { $$ = MASK(MINUTE); }
- | SECOND_P { $$ = MASK(SECOND); }
- | YEAR_P TO MONTH_P
- { $$ = MASK(YEAR) | MASK(MONTH); }
- | DAY_P TO HOUR_P
- { $$ = MASK(DAY) | MASK(HOUR); }
- | DAY_P TO MINUTE_P
- { $$ = MASK(DAY) | MASK(HOUR) | MASK(MINUTE); }
- | DAY_P TO SECOND_P
- { $$ = MASK(DAY) | MASK(HOUR) | MASK(MINUTE) | MASK(SECOND); }
- | HOUR_P TO MINUTE_P
- { $$ = MASK(HOUR) | MASK(MINUTE); }
- | HOUR_P TO SECOND_P
- { $$ = MASK(HOUR) | MASK(MINUTE) | MASK(SECOND); }
- | MINUTE_P TO SECOND_P
- { $$ = MASK(MINUTE) | MASK(SECOND); }
- | /*EMPTY*/ { $$ = -1; }
- ;
-
-
-/*****************************************************************************
- *
- * expression grammar
- *
- *****************************************************************************/
-
-/* Expressions using row descriptors
- * Define row_descriptor to allow yacc to break the reduce/reduce conflict
- * with singleton expressions.
- */
-row_expr: '(' row_descriptor ')' IN_P select_with_parens
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = $2;
- n->oper = (List *) makeSimpleA_Expr(OP, "=", NULL, NULL);
- n->useor = FALSE;
- n->subLinkType = ANY_SUBLINK;
- n->subselect = $5;
- $$ = (Node *)n;
- }
- | '(' row_descriptor ')' NOT IN_P select_with_parens
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = $2;
- n->oper = (List *) makeSimpleA_Expr(OP, "<>", NULL, NULL);
- n->useor = TRUE;
- n->subLinkType = ALL_SUBLINK;
- n->subselect = $6;
- $$ = (Node *)n;
- }
- | '(' row_descriptor ')' qual_all_Op sub_type select_with_parens
- %prec Op
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = $2;
- n->oper = (List *) makeA_Expr(OP, $4, NULL, NULL);
- if (strcmp(strVal(llast($4)), "<>") == 0)
- n->useor = TRUE;
- else
- n->useor = FALSE;
- n->subLinkType = $5;
- n->subselect = $6;
- $$ = (Node *)n;
- }
- | '(' row_descriptor ')' qual_all_Op select_with_parens
- %prec Op
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = $2;
- n->oper = (List *) makeA_Expr(OP, $4, NULL, NULL);
- if (strcmp(strVal(llast($4)), "<>") == 0)
- n->useor = TRUE;
- else
- n->useor = FALSE;
- n->subLinkType = MULTIEXPR_SUBLINK;
- n->subselect = $5;
- $$ = (Node *)n;
- }
- | '(' row_descriptor ')' qual_all_Op '(' row_descriptor ')'
- %prec Op
- {
- $$ = makeRowExpr($4, $2, $6);
- }
- | '(' row_descriptor ')' OVERLAPS '(' row_descriptor ')'
- {
- FuncCall *n = makeNode(FuncCall);
- List *largs = $2;
- List *rargs = $6;
- n->funcname = SystemFuncName("overlaps");
- if (length(largs) == 1)
- largs = lappend(largs, $2);
- else if (length(largs) != 2)
- elog(ERROR, "Wrong number of parameters"
- " on left side of OVERLAPS expression");
- if (length(rargs) == 1)
- rargs = lappend(rargs, $6);
- else if (length(rargs) != 2)
- elog(ERROR, "Wrong number of parameters"
- " on right side of OVERLAPS expression");
- n->args = nconc(largs, rargs);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- ;
-
-row_descriptor:
- row_list ',' a_expr { $$ = lappend($1, $3); }
- ;
-
-row_list: a_expr { $$ = makeList1($1); }
- | row_list ',' a_expr { $$ = lappend($1, $3); }
- ;
-
-sub_type: ANY { $$ = ANY_SUBLINK; }
- | SOME { $$ = ANY_SUBLINK; }
- | ALL { $$ = ALL_SUBLINK; }
- ;
-
-all_Op: Op { $$ = $1; }
- | MathOp { $$ = $1; }
- ;
-
-MathOp: '+' { $$ = "+"; }
- | '-' { $$ = "-"; }
- | '*' { $$ = "*"; }
- | '/' { $$ = "/"; }
- | '%' { $$ = "%"; }
- | '^' { $$ = "^"; }
- | '<' { $$ = "<"; }
- | '>' { $$ = ">"; }
- | '=' { $$ = "="; }
- ;
-
-qual_Op: Op
- { $$ = makeList1(makeString($1)); }
- | OPERATOR '(' any_operator ')' { $$ = $3; }
- ;
-
-qual_all_Op:
- all_Op
- { $$ = makeList1(makeString($1)); }
- | OPERATOR '(' any_operator ')' { $$ = $3; }
- ;
-
-/*
- * General expressions
- * This is the heart of the expression syntax.
- *
- * We have two expression types: a_expr is the unrestricted kind, and
- * b_expr is a subset that must be used in some places to avoid shift/reduce
- * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
- * because that use of AND conflicts with AND as a boolean operator. So,
- * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
- *
- * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
- * always be used by surrounding it with parens.
- *
- * c_expr is all the productions that are common to a_expr and b_expr;
- * it's factored out just to eliminate redundant coding.
- */
-a_expr: c_expr { $$ = $1; }
- | a_expr TYPECAST Typename
- { $$ = makeTypeCast($1, $3); }
- | a_expr COLLATE ColId
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName($3);
- n->args = makeList1($1);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) n;
- }
- | a_expr AT TIME ZONE c_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("timezone");
- n->args = makeList2($5, $1);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) n;
- }
- /*
- * These operators must be called out explicitly in order to make use
- * of yacc/bison's automatic operator-precedence handling. All other
- * operator names are handled by the generic productions using "Op",
- * below; and all those operators will have the same precedence.
- *
- * If you add more explicitly-known operators, be sure to add them
- * also to b_expr and to the MathOp list above.
- */
- | '+' a_expr %prec UMINUS
- { $$ = (Node *) makeSimpleA_Expr(OP, "+", NULL, $2); }
- | '-' a_expr %prec UMINUS
- { $$ = doNegate($2); }
- | '%' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", NULL, $2); }
- | '^' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", NULL, $2); }
- | a_expr '%'
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", $1, NULL); }
- | a_expr '^'
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", $1, NULL); }
- | a_expr '+' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "+", $1, $3); }
- | a_expr '-' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "-", $1, $3); }
- | a_expr '*' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "*", $1, $3); }
- | a_expr '/' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "/", $1, $3); }
- | a_expr '%' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", $1, $3); }
- | a_expr '^' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", $1, $3); }
- | a_expr '<' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "<", $1, $3); }
- | a_expr '>' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, ">", $1, $3); }
- | a_expr '=' a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "=", $1, $3); }
-
- | a_expr qual_Op a_expr %prec Op
- { $$ = (Node *) makeA_Expr(OP, $2, $1, $3); }
- | qual_Op a_expr %prec Op
- { $$ = (Node *) makeA_Expr(OP, $1, NULL, $2); }
- | a_expr qual_Op %prec POSTFIXOP
- { $$ = (Node *) makeA_Expr(OP, $2, $1, NULL); }
-
- | a_expr AND a_expr
- { $$ = (Node *) makeA_Expr(AND, NIL, $1, $3); }
- | a_expr OR a_expr
- { $$ = (Node *) makeA_Expr(OR, NIL, $1, $3); }
- | NOT a_expr
- { $$ = (Node *) makeA_Expr(NOT, NIL, NULL, $2); }
-
- | a_expr LIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "~~", $1, $3); }
- | a_expr LIKE a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($3, $5);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "~~", $1, (Node *) n);
- }
- | a_expr NOT LIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "!~~", $1, $4); }
- | a_expr NOT LIKE a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($4, $6);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "!~~", $1, (Node *) n);
- }
- | a_expr ILIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "~~*", $1, $3); }
- | a_expr ILIKE a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($3, $5);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "~~*", $1, (Node *) n);
- }
- | a_expr NOT ILIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "!~~*", $1, $4); }
- | a_expr NOT ILIKE a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($4, $6);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "!~~*", $1, (Node *) n);
- }
-
- | a_expr SIMILAR TO a_expr %prec SIMILAR
- { $$ = (Node *) makeSimpleA_Expr(OP, "~", $1, $4); }
- | a_expr SIMILAR TO a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($4, $6);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "~", $1, (Node *) n);
- }
- | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
- { $$ = (Node *) makeSimpleA_Expr(OP, "!~", $1, $5); }
- | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("like_escape");
- n->args = makeList2($5, $7);
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(OP, "!~", $1, (Node *) n);
- }
-
- /* NullTest clause
- * Define SQL92-style Null test clause.
- * Allow two forms described in the standard:
- * a IS NULL
- * a IS NOT NULL
- * Allow two SQL extensions
- * a ISNULL
- * a NOTNULL
- * NOTE: this is not yet fully SQL-compatible, since SQL92
- * allows a row constructor as argument, not just a scalar.
- */
- | a_expr ISNULL
- {
- NullTest *n = makeNode(NullTest);
- n->arg = $1;
- n->nulltesttype = IS_NULL;
- $$ = (Node *)n;
- }
- | a_expr IS NULL_P
- {
- NullTest *n = makeNode(NullTest);
- n->arg = $1;
- n->nulltesttype = IS_NULL;
- $$ = (Node *)n;
- }
- | a_expr NOTNULL
- {
- NullTest *n = makeNode(NullTest);
- n->arg = $1;
- n->nulltesttype = IS_NOT_NULL;
- $$ = (Node *)n;
- }
- | a_expr IS NOT NULL_P
- {
- NullTest *n = makeNode(NullTest);
- n->arg = $1;
- n->nulltesttype = IS_NOT_NULL;
- $$ = (Node *)n;
- }
- /* IS TRUE, IS FALSE, etc used to be function calls
- * but let's make them expressions to allow the optimizer
- * a chance to eliminate them if a_expr is a constant string.
- * - thomas 1997-12-22
- *
- * Created BooleanTest Node type, and changed handling
- * for NULL inputs
- * - jec 2001-06-18
- */
- | a_expr IS TRUE_P
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_TRUE;
- $$ = (Node *)b;
- }
- | a_expr IS NOT TRUE_P
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_NOT_TRUE;
- $$ = (Node *)b;
- }
- | a_expr IS FALSE_P
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_FALSE;
- $$ = (Node *)b;
- }
- | a_expr IS NOT FALSE_P
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_NOT_FALSE;
- $$ = (Node *)b;
- }
- | a_expr IS UNKNOWN
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_UNKNOWN;
- $$ = (Node *)b;
- }
- | a_expr IS NOT UNKNOWN
- {
- BooleanTest *b = makeNode(BooleanTest);
- b->arg = $1;
- b->booltesttype = IS_NOT_UNKNOWN;
- $$ = (Node *)b;
- }
- | a_expr BETWEEN b_expr AND b_expr %prec BETWEEN
- {
- $$ = (Node *) makeA_Expr(AND, NIL,
- (Node *) makeSimpleA_Expr(OP, ">=", $1, $3),
- (Node *) makeSimpleA_Expr(OP, "<=", $1, $5));
- }
- | a_expr NOT BETWEEN b_expr AND b_expr %prec BETWEEN
- {
- $$ = (Node *) makeA_Expr(OR, NIL,
- (Node *) makeSimpleA_Expr(OP, "<", $1, $4),
- (Node *) makeSimpleA_Expr(OP, ">", $1, $6));
- }
- | a_expr IN_P in_expr
- {
- /* in_expr returns a SubLink or a list of a_exprs */
- if (IsA($3, SubLink))
- {
- SubLink *n = (SubLink *)$3;
- n->lefthand = makeList1($1);
- n->oper = (List *) makeSimpleA_Expr(OP, "=",
- NULL, NULL);
- n->useor = FALSE;
- n->subLinkType = ANY_SUBLINK;
- $$ = (Node *)n;
- }
- else
- {
- Node *n = NULL;
- List *l;
- foreach(l, (List *) $3)
- {
- Node *cmp;
- cmp = (Node *) makeSimpleA_Expr(OP, "=",
- $1, lfirst(l));
- if (n == NULL)
- n = cmp;
- else
- n = (Node *) makeA_Expr(OR, NIL, n, cmp);
- }
- $$ = n;
- }
- }
- | a_expr NOT IN_P in_expr
- {
- /* in_expr returns a SubLink or a list of a_exprs */
- if (IsA($4, SubLink))
- {
- SubLink *n = (SubLink *)$4;
- n->lefthand = makeList1($1);
- n->oper = (List *) makeSimpleA_Expr(OP, "<>",
- NULL, NULL);
- n->useor = FALSE;
- n->subLinkType = ALL_SUBLINK;
- $$ = (Node *)n;
- }
- else
- {
- Node *n = NULL;
- List *l;
- foreach(l, (List *) $4)
- {
- Node *cmp;
- cmp = (Node *) makeSimpleA_Expr(OP, "<>",
- $1, lfirst(l));
- if (n == NULL)
- n = cmp;
- else
- n = (Node *) makeA_Expr(AND, NIL, n, cmp);
- }
- $$ = n;
- }
- }
- | a_expr qual_all_Op sub_type select_with_parens %prec Op
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = makeList1($1);
- n->oper = (List *) makeA_Expr(OP, $2, NULL, NULL);
- n->useor = FALSE; /* doesn't matter since only one col */
- n->subLinkType = $3;
- n->subselect = $4;
- $$ = (Node *)n;
- }
- | row_expr
- { $$ = $1; }
- ;
-
-/*
- * Restricted expressions
- *
- * b_expr is a subset of the complete expression syntax defined by a_expr.
- *
- * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
- * cause trouble in the places where b_expr is used. For simplicity, we
- * just eliminate all the boolean-keyword-operator productions from b_expr.
- */
-b_expr: c_expr
- { $$ = $1; }
- | b_expr TYPECAST Typename
- { $$ = makeTypeCast($1, $3); }
- | '+' b_expr %prec UMINUS
- { $$ = (Node *) makeSimpleA_Expr(OP, "+", NULL, $2); }
- | '-' b_expr %prec UMINUS
- { $$ = doNegate($2); }
- | '%' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", NULL, $2); }
- | '^' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", NULL, $2); }
- | b_expr '%'
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", $1, NULL); }
- | b_expr '^'
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", $1, NULL); }
- | b_expr '+' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "+", $1, $3); }
- | b_expr '-' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "-", $1, $3); }
- | b_expr '*' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "*", $1, $3); }
- | b_expr '/' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "/", $1, $3); }
- | b_expr '%' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "%", $1, $3); }
- | b_expr '^' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "^", $1, $3); }
- | b_expr '<' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "<", $1, $3); }
- | b_expr '>' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, ">", $1, $3); }
- | b_expr '=' b_expr
- { $$ = (Node *) makeSimpleA_Expr(OP, "=", $1, $3); }
- | b_expr qual_Op b_expr %prec Op
- { $$ = (Node *) makeA_Expr(OP, $2, $1, $3); }
- | qual_Op b_expr %prec Op
- { $$ = (Node *) makeA_Expr(OP, $1, NULL, $2); }
- | b_expr qual_Op %prec POSTFIXOP
- { $$ = (Node *) makeA_Expr(OP, $2, $1, NULL); }
- ;
-
-/*
- * Productions that can be used in both a_expr and b_expr.
- *
- * Note: productions that refer recursively to a_expr or b_expr mostly
- * cannot appear here. However, it's OK to refer to a_exprs that occur
- * inside parentheses, such as function arguments; that cannot introduce
- * ambiguity to the b_expr syntax.
- */
-c_expr: columnref { $$ = (Node *) $1; }
- | AexprConst { $$ = $1; }
- | PARAM attrs opt_indirection
- {
- /*
- * PARAM without field names is considered a constant,
- * but with 'em, it is not. Not very consistent ...
- */
- ParamRef *n = makeNode(ParamRef);
- n->number = $1;
- n->fields = $2;
- n->indirection = $3;
- $$ = (Node *)n;
- }
- | '(' a_expr ')' { $$ = $2; }
- | '(' a_expr ')' attrs opt_indirection
- {
- ExprFieldSelect *n = makeNode(ExprFieldSelect);
- n->arg = $2;
- n->fields = $4;
- n->indirection = $5;
- $$ = (Node *)n;
- }
- | CAST '(' a_expr AS Typename ')'
- { $$ = makeTypeCast($3, $5); }
- | case_expr
- { $$ = $1; }
- | func_name '(' ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = NIL;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | func_name '(' expr_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | func_name '(' ALL expr_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = $4;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- /* Ideally we'd mark the FuncCall node to indicate
- * "must be an aggregate", but there's no provision
- * for that in FuncCall at the moment.
- */
- $$ = (Node *)n;
- }
- | func_name '(' DISTINCT expr_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = $1;
- n->args = $4;
- n->agg_star = FALSE;
- n->agg_distinct = TRUE;
- $$ = (Node *)n;
- }
- | func_name '(' '*' ')'
- {
- /*
- * For now, we transform AGGREGATE(*) into AGGREGATE(1).
- *
- * This does the right thing for COUNT(*) (in fact,
- * any certainly-non-null expression would do for COUNT),
- * and there are no other aggregates in SQL92 that accept
- * '*' as parameter.
- *
- * The FuncCall node is also marked agg_star = true,
- * so that later processing can detect what the argument
- * really was.
- */
- FuncCall *n = makeNode(FuncCall);
- A_Const *star = makeNode(A_Const);
-
- star->val.type = T_Integer;
- star->val.val.ival = 1;
- n->funcname = $1;
- n->args = makeList1(star);
- n->agg_star = TRUE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | CURRENT_DATE
- {
- /*
- * Translate as "'now'::text::date".
- *
- * We cannot use "'now'::date" because coerce_type() will
- * immediately reduce that to a constant representing
- * today's date. We need to delay the conversion until
- * runtime, else the wrong things will happen when
- * CURRENT_DATE is used in a column default value or rule.
- *
- * This could be simplified if we had a way to generate
- * an expression tree representing runtime application
- * of type-input conversion functions...
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("date");
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | CURRENT_TIME
- {
- /*
- * Translate as "'now'::text::timetz".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("timetz");
- /* SQL99 mandates a default precision of zero for TIME
- * fields in schemas. However, for CURRENT_TIME
- * let's preserve the microsecond precision we
- * might see from the system clock. - thomas 2001-12-07
- */
- d->typmod = 6;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | CURRENT_TIME '(' Iconst ')'
- {
- /*
- * Translate as "'now'::text::timetz(n)".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
- d = SystemTypeName("timetz");
- if (($3 < 0) || ($3 > MAX_TIME_PRECISION))
- elog(ERROR,
- "CURRENT_TIME(%d) precision must be between %d and %d",
- $3, 0, MAX_TIME_PRECISION);
- d->typmod = $3;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | CURRENT_TIMESTAMP
- {
- /*
- * Translate as "'now'::text::timestamptz".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("timestamptz");
- /* SQL99 mandates a default precision of 6 for timestamp.
- * Also, that is about as precise as we will get since
- * we are using a microsecond time interface.
- * - thomas 2001-12-07
- */
- d->typmod = 6;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | CURRENT_TIMESTAMP '(' Iconst ')'
- {
- /*
- * Translate as "'now'::text::timestamptz(n)".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("timestamptz");
- if (($3 < 0) || ($3 > MAX_TIMESTAMP_PRECISION))
- elog(ERROR,
- "CURRENT_TIMESTAMP(%d) precision "
- "must be between %d and %d",
- $3, 0, MAX_TIMESTAMP_PRECISION);
- d->typmod = $3;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | LOCALTIME
- {
- /*
- * Translate as "'now'::text::time".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("time");
- /* SQL99 mandates a default precision of zero for TIME
- * fields in schemas. However, for LOCALTIME
- * let's preserve the microsecond precision we
- * might see from the system clock. - thomas 2001-12-07
- */
- d->typmod = 6;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | LOCALTIME '(' Iconst ')'
- {
- /*
- * Translate as "'now'::text::time(n)".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
- d = SystemTypeName("time");
- if (($3 < 0) || ($3 > MAX_TIME_PRECISION))
- elog(ERROR,
- "LOCALTIME(%d) precision must be between %d and %d",
- $3, 0, MAX_TIME_PRECISION);
- d->typmod = $3;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | LOCALTIMESTAMP
- {
- /*
- * Translate as "'now'::text::timestamp".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("timestamp");
- /* SQL99 mandates a default precision of 6 for timestamp.
- * Also, that is about as precise as we will get since
- * we are using a microsecond time interface.
- * - thomas 2001-12-07
- */
- d->typmod = 6;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | LOCALTIMESTAMP '(' Iconst ')'
- {
- /*
- * Translate as "'now'::text::timestamp(n)".
- * See comments for CURRENT_DATE.
- */
- A_Const *s = makeNode(A_Const);
- TypeName *d;
-
- s->val.type = T_String;
- s->val.val.str = "now";
- s->typename = SystemTypeName("text");
-
- d = SystemTypeName("timestamp");
- if (($3 < 0) || ($3 > MAX_TIMESTAMP_PRECISION))
- elog(ERROR,
- "LOCALTIMESTAMP(%d) precision must be "
- "between %d and %d",
- $3, 0, MAX_TIMESTAMP_PRECISION);
- d->typmod = $3;
-
- $$ = (Node *)makeTypeCast((Node *)s, d);
- }
- | CURRENT_USER
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("current_user");
- n->args = NIL;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | SESSION_USER
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("session_user");
- n->args = NIL;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | USER
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("current_user");
- n->args = NIL;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | EXTRACT '(' extract_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("date_part");
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | OVERLAY '(' overlay_list ')'
- {
- /* overlay(A PLACING B FROM C FOR D) is converted to
- * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
- * overlay(A PLACING B FROM C) is converted to
- * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
- */
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("overlay");
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | POSITION '(' position_list ')'
- {
- /* position(A in B) is converted to position(B, A) */
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("position");
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | SUBSTRING '(' substr_list ')'
- {
- /* substring(A from B for C) is converted to
- * substring(A, B, C) - thomas 2000-11-28
- */
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("substring");
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | TRIM '(' BOTH trim_list ')'
- {
- /* various trim expressions are defined in SQL92
- * - thomas 1997-07-19
- */
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("btrim");
- n->args = $4;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | TRIM '(' LEADING trim_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("ltrim");
- n->args = $4;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | TRIM '(' TRAILING trim_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("rtrim");
- n->args = $4;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | TRIM '(' trim_list ')'
- {
- FuncCall *n = makeNode(FuncCall);
- n->funcname = SystemFuncName("btrim");
- n->args = $3;
- n->agg_star = FALSE;
- n->agg_distinct = FALSE;
- $$ = (Node *)n;
- }
- | select_with_parens %prec UMINUS
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = NIL;
- n->oper = NIL;
- n->useor = FALSE;
- n->subLinkType = EXPR_SUBLINK;
- n->subselect = $1;
- $$ = (Node *)n;
- }
- | EXISTS select_with_parens
- {
- SubLink *n = makeNode(SubLink);
- n->lefthand = NIL;
- n->oper = NIL;
- n->useor = FALSE;
- n->subLinkType = EXISTS_SUBLINK;
- n->subselect = $2;
- $$ = (Node *)n;
- }
- ;
-
-/*
- * Supporting nonterminals for expressions.
- */
-
-opt_indirection:
- opt_indirection '[' a_expr ']'
- {
- A_Indices *ai = makeNode(A_Indices);
- ai->lidx = NULL;
- ai->uidx = $3;
- $$ = lappend($1, ai);
- }
- | opt_indirection '[' a_expr ':' a_expr ']'
- {
- A_Indices *ai = makeNode(A_Indices);
- ai->lidx = $3;
- ai->uidx = $5;
- $$ = lappend($1, ai);
- }
- | /*EMPTY*/
- { $$ = NIL; }
- ;
-
-expr_list: a_expr { $$ = makeList1($1); }
- | expr_list ',' a_expr { $$ = lappend($1, $3); }
- | expr_list USING a_expr { $$ = lappend($1, $3); }
- ;
-
-extract_list:
- extract_arg FROM a_expr
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = $1;
- $$ = makeList2((Node *) n, $3);
- }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-/* Allow delimited string SCONST in extract_arg as an SQL extension.
- * - thomas 2001-04-12
- */
-
-extract_arg:
- IDENT { $$ = $1; }
- | YEAR_P { $$ = "year"; }
- | MONTH_P { $$ = "month"; }
- | DAY_P { $$ = "day"; }
- | HOUR_P { $$ = "hour"; }
- | MINUTE_P { $$ = "minute"; }
- | SECOND_P { $$ = "second"; }
- | SCONST { $$ = $1; }
- ;
-
-/* OVERLAY() arguments
- * SQL99 defines the OVERLAY() function:
- * o overlay(text placing text from int for int)
- * o overlay(text placing text from int)
- */
-overlay_list:
- a_expr overlay_placing substr_from substr_for
- {
- $$ = makeList4($1, $2, $3, $4);
- }
- | a_expr overlay_placing substr_from
- {
- $$ = makeList3($1, $2, $3);
- }
- ;
-
-overlay_placing:
- PLACING a_expr
- { $$ = $2; }
- ;
-
-/* position_list uses b_expr not a_expr to avoid conflict with general IN */
-
-position_list:
- b_expr IN_P b_expr { $$ = makeList2($3, $1); }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-/* SUBSTRING() arguments
- * SQL9x defines a specific syntax for arguments to SUBSTRING():
- * o substring(text from int for int)
- * o substring(text from int) get entire string from starting point "int"
- * o substring(text for int) get first "int" characters of string
- * We also want to implement generic substring functions which accept
- * the usual generic list of arguments. So we will accept both styles
- * here, and convert the SQL9x style to the generic list for further
- * processing. - thomas 2000-11-28
- */
-substr_list:
- a_expr substr_from substr_for
- {
- $$ = makeList3($1, $2, $3);
- }
- | a_expr substr_for substr_from
- {
- $$ = makeList3($1, $3, $2);
- }
- | a_expr substr_from
- {
- $$ = makeList2($1, $2);
- }
- | a_expr substr_for
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Integer;
- n->val.val.ival = 1;
- $$ = makeList3($1, (Node *)n, $2);
- }
- | expr_list
- {
- $$ = $1;
- }
- | /*EMPTY*/
- { $$ = NIL; }
- ;
-
-substr_from:
- FROM a_expr { $$ = $2; }
- ;
-
-substr_for: FOR a_expr { $$ = $2; }
- ;
-
-trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
- | FROM expr_list { $$ = $2; }
- | expr_list { $$ = $1; }
- ;
-
-in_expr: select_with_parens
- {
- SubLink *n = makeNode(SubLink);
- n->subselect = $1;
- $$ = (Node *)n;
- }
- | '(' in_expr_nodes ')' { $$ = (Node *)$2; }
- ;
-
-in_expr_nodes:
- a_expr { $$ = makeList1($1); }
- | in_expr_nodes ',' a_expr { $$ = lappend($1, $3); }
- ;
-
-/* Case clause
- * Define SQL92-style case clause.
- * Allow all four forms described in the standard:
- * - Full specification
- * CASE WHEN a = b THEN c ... ELSE d END
- * - Implicit argument
- * CASE a WHEN b THEN c ... ELSE d END
- * - Conditional NULL
- * NULLIF(x,y)
- * same as CASE WHEN x = y THEN NULL ELSE x END
- * - Conditional substitution from list, use first non-null argument
- * COALESCE(a,b,...)
- * same as CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ... END
- * - thomas 1998-11-09
- */
-case_expr: CASE case_arg when_clause_list case_default END_TRANS
- {
- CaseExpr *c = makeNode(CaseExpr);
- c->arg = $2;
- c->args = $3;
- c->defresult = $4;
- $$ = (Node *)c;
- }
- | NULLIF '(' a_expr ',' a_expr ')'
- {
- CaseExpr *c = makeNode(CaseExpr);
- CaseWhen *w = makeNode(CaseWhen);
-
- w->expr = (Node *) makeSimpleA_Expr(OP, "=", $3, $5);
- /* w->result is left NULL */
- c->args = makeList1(w);
- c->defresult = $3;
- $$ = (Node *)c;
- }
- | COALESCE '(' expr_list ')'
- {
- CaseExpr *c = makeNode(CaseExpr);
- List *l;
- foreach (l,$3)
- {
- CaseWhen *w = makeNode(CaseWhen);
- NullTest *n = makeNode(NullTest);
- n->arg = lfirst(l);
- n->nulltesttype = IS_NOT_NULL;
- w->expr = (Node *) n;
- w->result = lfirst(l);
- c->args = lappend(c->args, w);
- }
- $$ = (Node *)c;
- }
- ;
-
-when_clause_list:
- /* There must be at least one */
- when_clause { $$ = makeList1($1); }
- | when_clause_list when_clause { $$ = lappend($1, $2); }
- ;
-
-when_clause:
- WHEN a_expr THEN a_expr
- {
- CaseWhen *w = makeNode(CaseWhen);
- w->expr = $2;
- w->result = $4;
- $$ = (Node *)w;
- }
- ;
-
-case_default:
- ELSE a_expr { $$ = $2; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-case_arg: a_expr { $$ = $1; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
-
-/*
- * columnref starts with relation_name not ColId, so that OLD and NEW
- * references can be accepted. Note that when there are more than two
- * dotted names, the first name is not actually a relation name...
- */
-columnref: relation_name opt_indirection
- {
- $$ = makeNode(ColumnRef);
- $$->fields = makeList1(makeString($1));
- $$->indirection = $2;
- }
- | dotted_name opt_indirection
- {
- $$ = makeNode(ColumnRef);
- $$->fields = $1;
- $$->indirection = $2;
- }
- ;
-
-dotted_name:
- relation_name attrs
- { $$ = lcons(makeString($1), $2); }
- ;
-
-attrs: '.' attr_name
- { $$ = makeList1(makeString($2)); }
- | '.' '*'
- { $$ = makeList1(makeString("*")); }
- | '.' attr_name attrs
- { $$ = lcons(makeString($2), $3); }
- ;
-
-
-/*****************************************************************************
- *
- * target lists
- *
- *****************************************************************************/
-
-/* Target lists as found in SELECT ... and INSERT VALUES ( ... ) */
-
-target_list:
- target_el { $$ = makeList1($1); }
- | target_list ',' target_el { $$ = lappend($1, $3); }
- ;
-
-/* AS is not optional because shift/red conflict with unary ops */
-target_el: a_expr AS ColLabel
- {
- $$ = makeNode(ResTarget);
- $$->name = $3;
- $$->indirection = NIL;
- $$->val = (Node *)$1;
- }
- | a_expr
- {
- $$ = makeNode(ResTarget);
- $$->name = NULL;
- $$->indirection = NIL;
- $$->val = (Node *)$1;
- }
- | '*'
- {
- ColumnRef *n = makeNode(ColumnRef);
- n->fields = makeList1(makeString("*"));
- n->indirection = NIL;
- $$ = makeNode(ResTarget);
- $$->name = NULL;
- $$->indirection = NIL;
- $$->val = (Node *)n;
- }
- ;
-
-/* Target list as found in UPDATE table SET ...
-| '(' row_ ')' = '(' row_ ')'
-{
- $$ = NULL;
-}
- */
-update_target_list:
- update_target_el { $$ = makeList1($1); }
- | update_target_list ',' update_target_el { $$ = lappend($1,$3); }
- ;
-
-update_target_el:
- ColId opt_indirection '=' a_expr
- {
- $$ = makeNode(ResTarget);
- $$->name = $1;
- $$->indirection = $2;
- $$->val = (Node *)$4;
- }
- ;
-
-insert_target_list:
- insert_target_el { $$ = makeList1($1); }
- | insert_target_list ',' insert_target_el { $$ = lappend($1, $3); }
- ;
-
-insert_target_el:
- target_el { $$ = $1; }
- | DEFAULT
- {
- InsertDefault *def = makeNode(InsertDefault);
- $$ = makeNode(ResTarget);
- $$->name = NULL;
- $$->indirection = NULL;
- $$->val = (Node *)def;
- }
- ;
-
-
-/*****************************************************************************
- *
- * Names and constants
- *
- *****************************************************************************/
-
-relation_name:
- SpecialRuleRelation { $$ = $1; }
- | ColId { $$ = $1; }
- ;
-
-qualified_name_list:
- qualified_name { $$ = makeList1($1); }
- | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
- ;
-
-qualified_name:
- relation_name
- {
- $$ = makeNode(RangeVar);
- $$->catalogname = NULL;
- $$->schemaname = NULL;
- $$->relname = $1;
- }
- | dotted_name
- {
- $$ = makeNode(RangeVar);
- switch (length($1))
- {
- case 2:
- $$->catalogname = NULL;
- $$->schemaname = strVal(lfirst($1));
- $$->relname = strVal(lsecond($1));
- break;
- case 3:
- $$->catalogname = strVal(lfirst($1));
- $$->schemaname = strVal(lsecond($1));
- $$->relname = strVal(lfirst(lnext(lnext($1))));
- break;
- default:
- elog(ERROR,
- "Improper qualified name "
- "(too many dotted names): %s",
- NameListToString($1));
- break;
- }
- }
- ;
-
-name_list: name
- { $$ = makeList1(makeString($1)); }
- | name_list ',' name
- { $$ = lappend($1, makeString($3)); }
- ;
-
-
-name: ColId { $$ = $1; };
-
-database_name:
- ColId { $$ = $1; };
-
-access_method:
- ColId { $$ = $1; };
-
-attr_name: ColId { $$ = $1; };
-
-index_name: ColId { $$ = $1; };
-
-file_name: Sconst { $$ = $1; };
-
-func_name: function_name
- { $$ = makeList1(makeString($1)); }
- | dotted_name { $$ = $1; }
- ;
-
-
-/* Constants
- * Include TRUE/FALSE for SQL3 support. - thomas 1997-10-24
- */
-AexprConst: Iconst
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Integer;
- n->val.val.ival = $1;
- $$ = (Node *)n;
- }
- | FCONST
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Float;
- n->val.val.str = $1;
- $$ = (Node *)n;
- }
- | Sconst
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = $1;
- $$ = (Node *)n;
- }
- | BITCONST
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_BitString;
- n->val.val.str = $1;
- $$ = (Node *)n;
- }
- /* This rule formerly used Typename,
- * but that causes reduce conflicts with subscripted column names.
- * Now, separate into ConstTypename and ConstInterval,
- * to allow implementing the SQL92 syntax for INTERVAL literals.
- * - thomas 2000-06-24
- */
- | ConstTypename Sconst
- {
- A_Const *n = makeNode(A_Const);
- n->typename = $1;
- n->val.type = T_String;
- n->val.val.str = $2;
- $$ = (Node *)n;
- }
- | ConstInterval Sconst opt_interval
- {
- A_Const *n = makeNode(A_Const);
- n->typename = $1;
- n->val.type = T_String;
- n->val.val.str = $2;
- /* precision is not specified, but fields may be... */
- if ($3 != -1)
- n->typename->typmod = ((($3 & 0x7FFF) << 16) | 0xFFFF);
- $$ = (Node *)n;
- }
- | ConstInterval '(' Iconst ')' Sconst opt_interval
- {
- A_Const *n = makeNode(A_Const);
- n->typename = $1;
- n->val.type = T_String;
- n->val.val.str = $5;
- /* precision specified, and fields may be... */
- if (($3 < 0) || ($3 > MAX_INTERVAL_PRECISION))
- elog(ERROR,
- "INTERVAL(%d) precision must be between %d and %d",
- $3, 0, MAX_INTERVAL_PRECISION);
- n->typename->typmod = ((($6 & 0x7FFF) << 16) | $3);
- $$ = (Node *)n;
- }
- | PARAM opt_indirection
- {
- ParamRef *n = makeNode(ParamRef);
- n->number = $1;
- n->fields = NIL;
- n->indirection = $2;
- $$ = (Node *)n;
- }
- | TRUE_P
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = "t";
- n->typename = SystemTypeName("bool");
- $$ = (Node *)n;
- }
- | FALSE_P
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = "f";
- n->typename = SystemTypeName("bool");
- $$ = (Node *)n;
- }
- | NULL_P
- {
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Null;
- $$ = (Node *)n;
- }
- ;
-
-Iconst: ICONST { $$ = $1; };
-Sconst: SCONST { $$ = $1; };
-UserId: ColId { $$ = $1; };
-
-/*
- * Name classification hierarchy.
- *
- * IDENT is the lexeme returned by the lexer for identifiers that match
- * no known keyword. In most cases, we can accept certain keywords as
- * names, not only IDENTs. We prefer to accept as many such keywords
- * as possible to minimize the impact of "reserved words" on programmers.
- * So, we divide names into several possible classes. The classification
- * is chosen in part to make keywords acceptable as names wherever possible.
- */
-
-/* Column identifier --- names that can be column, table, etc names.
- */
-ColId: IDENT { $$ = $1; }
- | unreserved_keyword { $$ = pstrdup($1); }
- | col_name_keyword { $$ = pstrdup($1); }
- ;
-
-/* Type identifier --- names that can be type names.
- */
-type_name: IDENT { $$ = $1; }
- | unreserved_keyword { $$ = pstrdup($1); }
- ;
-
-/* Function identifier --- names that can be function names.
- */
-function_name:
- IDENT { $$ = $1; }
- | unreserved_keyword { $$ = pstrdup($1); }
- | func_name_keyword { $$ = pstrdup($1); }
- ;
-
-/* Column label --- allowed labels in "AS" clauses.
- * This presently includes *all* Postgres keywords.
- */
-ColLabel: IDENT { $$ = $1; }
- | unreserved_keyword { $$ = pstrdup($1); }
- | col_name_keyword { $$ = pstrdup($1); }
- | func_name_keyword { $$ = pstrdup($1); }
- | reserved_keyword { $$ = pstrdup($1); }
- ;
-
-
-/*
- * Keyword classification lists. Generally, every keyword present in
- * the Postgres grammar should appear in exactly one of these lists.
- *
- * Put a new keyword into the first list that it can go into without causing
- * shift or reduce conflicts. The earlier lists define "less reserved"
- * categories of keywords.
- */
-
-/* "Unreserved" keywords --- available for use as any kind of name.
- */
-unreserved_keyword:
- ABORT_TRANS
- | ABSOLUTE
- | ACCESS
- | ACTION
- | ADD
- | AFTER
- | AGGREGATE
- | ALTER
- | ASSERTION
- | AT
- | BACKWARD
- | BEFORE
- | BEGIN_TRANS
- | BY
- | CACHE
- | CALLED
- | CASCADE
- | CHAIN
- | CHARACTERISTICS
- | CHECKPOINT
- | CLOSE
- | CLUSTER
- | COMMENT
- | COMMIT
- | COMMITTED
- | CONSTRAINTS
- | COPY
- | CREATEDB
- | CREATEUSER
- | CURSOR
- | CYCLE
- | DATABASE
- | DAY_P
- | DECLARE
- | DEFERRED
- | DEFINER
- | DELETE_P
- | DELIMITER
- | DELIMITERS
- | DOMAIN_P
- | DOUBLE
- | DROP
- | EACH
- | ENCODING
- | ENCRYPTED
- | ESCAPE
- | EXCLUSIVE
- | EXECUTE
- | EXPLAIN
- | EXTERNAL
- | FETCH
- | FORCE
- | FORWARD
- | FUNCTION
- | GET
- | GLOBAL
- | HANDLER
- | HOUR_P
- | IMMEDIATE
- | IMMUTABLE
- | IMPLICIT
- | INCREMENT
- | INDEX
- | INHERITS
- | INOUT
- | INPUT
- | INSENSITIVE
- | INSERT
- | INSTEAD
- | INVOKER
- | ISOLATION
- | KEY
- | LANGUAGE
- | LANCOMPILER
- | LEVEL
- | LISTEN
- | LOAD
- | LOCAL
- | LOCATION
- | LOCK_P
- | MATCH
- | MAXVALUE
- | MINUTE_P
- | MINVALUE
- | MODE
- | MONTH_P
- | MOVE
- | NAMES
- | NATIONAL
- | NEXT
- | NO
- | NOCREATEDB
- | NOCREATEUSER
- | NOTHING
- | NOTIFY
- | OF
- | OIDS
- | OPERATOR
- | OPTION
- | OUT_P
- | OWNER
- | PARTIAL
- | PASSWORD
- | PATH_P
- | PENDANT
- | PRECISION
- | PRIOR
- | PRIVILEGES
- | PROCEDURAL
- | PROCEDURE
- | READ
- | REINDEX
- | RELATIVE
- | RENAME
- | REPLACE
- | RESET
- | RESTRICT
- | RETURNS
- | REVOKE
- | ROLLBACK
- | ROW
- | RULE
- | SCHEMA
- | SCROLL
- | SECOND_P
- | SECURITY
- | SESSION
- | SEQUENCE
- | SERIALIZABLE
- | SET
- | SHARE
- | SHOW
- | STABLE
- | START
- | STATEMENT
- | STATISTICS
- | STDIN
- | STDOUT
- | STORAGE
- | STRICT
- | SYSID
- | TEMP
- | TEMPLATE
- | TEMPORARY
- | TOAST
- | TRANSACTION
- | TRIGGER
- | TRUNCATE
- | TRUSTED
- | TYPE_P
- | UNENCRYPTED
- | UNKNOWN
- | UNLISTEN
- | UNTIL
- | UPDATE
- | USAGE
- | VACUUM
- | VALID
- | VALIDATOR
- | VALUES
- | VARYING
- | VERSION
- | VIEW
- | VOLATILE
- | WITH
- | WITHOUT
- | WORK
- | YEAR_P
- | ZONE
- ;
-
-/* Column identifier --- keywords that can be column, table, etc names.
- *
- * Many of these keywords will in fact be recognized as type or function
- * names too; but they have special productions for the purpose, and so
- * can't be treated as "generic" type or function names.
- *
- * The type names appearing here are not usable as function names
- * because they can be followed by '(' in typename productions, which
- * looks too much like a function call for an LR(1) parser.
- */
-col_name_keyword:
- BIGINT
- | BIT
- | BOOLEAN
- | CHAR_P
- | CHARACTER
- | COALESCE
- | DEC
- | DECIMAL
- | EXISTS
- | EXTRACT
- | FLOAT_P
- | INT
- | INTEGER
- | INTERVAL
- | NCHAR
- | NONE
- | NULLIF
- | NUMERIC
- | OVERLAY
- | POSITION
- | REAL
- | SETOF
- | SMALLINT
- | SUBSTRING
- | TIME
- | TIMESTAMP
- | TRIM
- | VARCHAR
- ;
-
-/* Function identifier --- keywords that can be function names.
- *
- * Most of these are keywords that are used as operators in expressions;
- * in general such keywords can't be column names because they would be
- * ambiguous with variables, but they are unambiguous as function identifiers.
- *
- * Do not include POSITION, SUBSTRING, etc here since they have explicit
- * productions in a_expr to support the goofy SQL9x argument syntax.
- * - thomas 2000-11-28
- */
-func_name_keyword:
- AUTHORIZATION
- | BETWEEN
- | BINARY
- | CROSS
- | FREEZE
- | FULL
- | ILIKE
- | IN_P
- | INNER_P
- | IS
- | ISNULL
- | JOIN
- | LEFT
- | LIKE
- | NATURAL
- | NOTNULL
- | OUTER_P
- | OVERLAPS
- | RIGHT
- | SIMILAR
- | VERBOSE
- ;
-
-/* Reserved keyword --- these keywords are usable only as a ColLabel.
- *
- * Keywords appear here if they could not be distinguished from variable,
- * type, or function names in some contexts. Don't put things here unless
- * forced to.
- */
-reserved_keyword:
- ALL
- | ANALYSE
- | ANALYZE
- | AND
- | ANY
- | AS
- | ASC
- | BOTH
- | CASE
- | CAST
- | CHECK
- | COLLATE
- | COLUMN
- | CONSTRAINT
- | CREATE
- | CURRENT_DATE
- | CURRENT_TIME
- | CURRENT_TIMESTAMP
- | CURRENT_USER
- | DEFAULT
- | DEFERRABLE
- | DESC
- | DISTINCT
- | DO
- | ELSE
- | END_TRANS
- | EXCEPT
- | FALSE_P
- | FOR
- | FOREIGN
- | FROM
- | GRANT
- | GROUP_P
- | HAVING
- | INITIALLY
- | INTERSECT
- | INTO
- | LEADING
- | LIMIT
- | LOCALTIME
- | LOCALTIMESTAMP
- | NEW
- | NOT
- | NULL_P
- | OFF
- | OFFSET
- | OLD
- | ON
- | ONLY
- | OR
- | ORDER
- | PLACING
- | PRIMARY
- | REFERENCES
- | SELECT
- | SESSION_USER
- | SOME
- | TABLE
- | THEN
- | TO
- | TRAILING
- | TRUE_P
- | UNION
- | UNIQUE
- | USER
- | USING
- | WHEN
- | WHERE
- ;
-
-
-SpecialRuleRelation:
- OLD
- {
- if (QueryIsRule)
- $$ = "*OLD*";
- else
- elog(ERROR, "OLD used in non-rule query");
- }
- | NEW
- {
- if (QueryIsRule)
- $$ = "*NEW*";
- else
- elog(ERROR, "NEW used in non-rule query");
- }
- ;
-
-%%
-
-static Node *
-makeTypeCast(Node *arg, TypeName *typename)
-{
- /*
- * If arg is an A_Const, just stick the typename into the
- * field reserved for it --- unless there's something there already!
- * (We don't want to collapse x::type1::type2 into just x::type2.)
- * Otherwise, generate a TypeCast node.
- */
- if (IsA(arg, A_Const) &&
- ((A_Const *) arg)->typename == NULL)
- {
- ((A_Const *) arg)->typename = typename;
- return arg;
- }
- else
- {
- TypeCast *n = makeNode(TypeCast);
- n->arg = arg;
- n->typename = typename;
- return (Node *) n;
- }
-}
-
-static Node *
-makeStringConst(char *str, TypeName *typename)
-{
- A_Const *n = makeNode(A_Const);
-
- n->val.type = T_String;
- n->val.val.str = str;
- n->typename = typename;
-
- return (Node *)n;
-}
-
-static Node *
-makeIntConst(int val)
-{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Integer;
- n->val.val.ival = val;
- n->typename = SystemTypeName("int4");
-
- return (Node *)n;
-}
-
-static Node *
-makeFloatConst(char *str)
-{
- A_Const *n = makeNode(A_Const);
-
- n->val.type = T_Float;
- n->val.val.str = str;
- n->typename = SystemTypeName("float8");
-
- return (Node *)n;
-}
-
-static Node *
-makeAConst(Value *v)
-{
- Node *n;
-
- switch (v->type)
- {
- case T_Float:
- n = makeFloatConst(v->val.str);
- break;
-
- case T_Integer:
- n = makeIntConst(v->val.ival);
- break;
-
- case T_String:
- default:
- n = makeStringConst(v->val.str, NULL);
- break;
- }
-
- return n;
-}
-
-/* makeRowExpr()
- * Generate separate operator nodes for a single row descriptor expression.
- * Perhaps this should go deeper in the parser someday...
- * - thomas 1997-12-22
- */
-static Node *
-makeRowExpr(List *opr, List *largs, List *rargs)
-{
- Node *expr = NULL;
- Node *larg, *rarg;
- char *oprname;
-
- if (length(largs) != length(rargs))
- elog(ERROR, "Unequal number of entries in row expression");
-
- if (lnext(largs) != NIL)
- expr = makeRowExpr(opr, lnext(largs), lnext(rargs));
-
- larg = lfirst(largs);
- rarg = lfirst(rargs);
-
- oprname = strVal(llast(opr));
-
- if ((strcmp(oprname, "=") == 0) ||
- (strcmp(oprname, "<") == 0) ||
- (strcmp(oprname, "<=") == 0) ||
- (strcmp(oprname, ">") == 0) ||
- (strcmp(oprname, ">=") == 0))
- {
- if (expr == NULL)
- expr = (Node *) makeA_Expr(OP, opr, larg, rarg);
- else
- expr = (Node *) makeA_Expr(AND, NIL, expr,
- (Node *) makeA_Expr(OP, opr,
- larg, rarg));
- }
- else if (strcmp(oprname, "<>") == 0)
- {
- if (expr == NULL)
- expr = (Node *) makeA_Expr(OP, opr, larg, rarg);
- else
- expr = (Node *) makeA_Expr(OR, NIL, expr,
- (Node *) makeA_Expr(OP, opr,
- larg, rarg));
- }
- else
- {
- elog(ERROR, "Operator '%s' not implemented for row expressions",
- oprname);
- }
-
- return expr;
-}
-
-/* findLeftmostSelect()
- * Find the leftmost component SelectStmt in a set-operation parsetree.
- */
-static SelectStmt *
-findLeftmostSelect(SelectStmt *node)
-{
- while (node && node->op != SETOP_NONE)
- node = node->larg;
- Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
- return node;
-}
-
-/* insertSelectOptions()
- * Insert ORDER BY, etc into an already-constructed SelectStmt.
- *
- * This routine is just to avoid duplicating code in SelectStmt productions.
- */
-static void
-insertSelectOptions(SelectStmt *stmt,
- List *sortClause, List *forUpdate,
- Node *limitOffset, Node *limitCount)
-{
- /*
- * Tests here are to reject constructs like
- * (SELECT foo ORDER BY bar) ORDER BY baz
- */
- if (sortClause)
- {
- if (stmt->sortClause)
- elog(ERROR, "Multiple ORDER BY clauses not allowed");
- stmt->sortClause = sortClause;
- }
- if (forUpdate)
- {
- if (stmt->forUpdate)
- elog(ERROR, "Multiple FOR UPDATE clauses not allowed");
- stmt->forUpdate = forUpdate;
- }
- if (limitOffset)
- {
- if (stmt->limitOffset)
- elog(ERROR, "Multiple OFFSET clauses not allowed");
- stmt->limitOffset = limitOffset;
- }
- if (limitCount)
- {
- if (stmt->limitCount)
- elog(ERROR, "Multiple LIMIT clauses not allowed");
- stmt->limitCount = limitCount;
- }
-}
-
-static Node *
-makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
-{
- SelectStmt *n = makeNode(SelectStmt);
-
- n->op = op;
- n->all = all;
- n->larg = (SelectStmt *) larg;
- n->rarg = (SelectStmt *) rarg;
- return (Node *) n;
-}
-
-/* SystemFuncName()
- * Build a properly-qualified reference to a built-in function.
- */
-List *
-SystemFuncName(char *name)
-{
- return makeList2(makeString("pg_catalog"), makeString(name));
-}
-
-/* SystemTypeName()
- * Build a properly-qualified reference to a built-in type.
- *
- * typmod is defaulted, but may be changed afterwards by caller.
- */
-TypeName *
-SystemTypeName(char *name)
-{
- TypeName *n = makeNode(TypeName);
-
- n->names = makeList2(makeString("pg_catalog"), makeString(name));
- n->typmod = -1;
- return n;
-}
-
-/*
- * Initialize to parse one query string
- */
-void
-parser_init(Oid *typev, int nargs)
-{
- QueryIsRule = FALSE;
- /*
- * Keep enough information around to fill out the type of param nodes
- * used in postquel functions
- */
- param_type_info = typev;
- pfunc_num_args = nargs;
-}
-
-/*
- * Fetch a parameter type previously passed to parser_init
- */
-Oid
-param_type(int t)
-{
- if ((t > pfunc_num_args) || (t <= 0))
- return InvalidOid;
- return param_type_info[t - 1];
-}
-
-/*
- * Test whether an a_expr is a plain NULL constant or not.
- */
-bool
-exprIsNullConstant(Node *arg)
-{
- if (arg && IsA(arg, A_Const))
- {
- A_Const *con = (A_Const *) arg;
-
- if (con->val.type == T_Null &&
- con->typename == NULL)
- return TRUE;
- }
- return FALSE;
-}
-
-/*
- * doNegate --- handle negation of a numeric constant.
- *
- * Formerly, we did this here because the optimizer couldn't cope with
- * indexquals that looked like "var = -4" --- it wants "var = const"
- * and a unary minus operator applied to a constant didn't qualify.
- * As of Postgres 7.0, that problem doesn't exist anymore because there
- * is a constant-subexpression simplifier in the optimizer. However,
- * there's still a good reason for doing this here, which is that we can
- * postpone committing to a particular internal representation for simple
- * negative constants. It's better to leave "-123.456" in string form
- * until we know what the desired type is.
- */
-static Node *
-doNegate(Node *n)
-{
- if (IsA(n, A_Const))
- {
- A_Const *con = (A_Const *)n;
-
- if (con->val.type == T_Integer)
- {
- con->val.val.ival = -con->val.val.ival;
- return n;
- }
- if (con->val.type == T_Float)
- {
- doNegateFloat(&con->val);
- return n;
- }
- }
-
- return (Node *) makeSimpleA_Expr(OP, "-", NULL, n);
-}
-
-static void
-doNegateFloat(Value *v)
-{
- char *oldval = v->val.str;
-
- Assert(IsA(v, Float));
- if (*oldval == '+')
- oldval++;
- if (*oldval == '-')
- v->val.str = oldval+1; /* just strip the '-' */
- else
- {
- char *newval = (char *) palloc(strlen(oldval) + 2);
-
- *newval = '-';
- strcpy(newval+1, oldval);
- v->val.str = newval;
- }
-}
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
deleted file mode 100644
index cdf79fea2dc..00000000000
--- a/src/backend/parser/keywords.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * keywords.c
- * lexical token lookup for reserved words in PostgreSQL
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.116 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <ctype.h>
-
-#include "nodes/parsenodes.h"
-#include "parser/keywords.h"
-#include "parser/parse.h"
-
-/*
- * List of (keyword-name, keyword-token-value) pairs.
- *
- * !!WARNING!!: This list must be sorted, because binary
- * search is used to locate entries.
- */
-static const ScanKeyword ScanKeywords[] = {
- /* name, value */
- {"abort", ABORT_TRANS},
- {"absolute", ABSOLUTE},
- {"access", ACCESS},
- {"action", ACTION},
- {"add", ADD},
- {"after", AFTER},
- {"aggregate", AGGREGATE},
- {"all", ALL},
- {"alter", ALTER},
- {"analyse", ANALYSE}, /* British spelling */
- {"analyze", ANALYZE},
- {"and", AND},
- {"any", ANY},
- {"as", AS},
- {"asc", ASC},
- {"assertion", ASSERTION},
- {"at", AT},
- {"authorization", AUTHORIZATION},
- {"backward", BACKWARD},
- {"before", BEFORE},
- {"begin", BEGIN_TRANS},
- {"between", BETWEEN},
- {"bigint", BIGINT},
- {"binary", BINARY},
- {"bit", BIT},
- {"boolean", BOOLEAN},
- {"both", BOTH},
- {"by", BY},
- {"cache", CACHE},
- {"called", CALLED},
- {"cascade", CASCADE},
- {"case", CASE},
- {"cast", CAST},
- {"chain", CHAIN},
- {"char", CHAR_P},
- {"character", CHARACTER},
- {"characteristics", CHARACTERISTICS},
- {"check", CHECK},
- {"checkpoint", CHECKPOINT},
- {"close", CLOSE},
- {"cluster", CLUSTER},
- {"coalesce", COALESCE},
- {"collate", COLLATE},
- {"column", COLUMN},
- {"comment", COMMENT},
- {"commit", COMMIT},
- {"committed", COMMITTED},
- {"constraint", CONSTRAINT},
- {"constraints", CONSTRAINTS},
- {"copy", COPY},
- {"create", CREATE},
- {"createdb", CREATEDB},
- {"createuser", CREATEUSER},
- {"cross", CROSS},
- {"current_date", CURRENT_DATE},
- {"current_time", CURRENT_TIME},
- {"current_timestamp", CURRENT_TIMESTAMP},
- {"current_user", CURRENT_USER},
- {"cursor", CURSOR},
- {"cycle", CYCLE},
- {"database", DATABASE},
- {"day", DAY_P},
- {"dec", DEC},
- {"decimal", DECIMAL},
- {"declare", DECLARE},
- {"default", DEFAULT},
- {"deferrable", DEFERRABLE},
- {"deferred", DEFERRED},
- {"definer", DEFINER},
- {"delete", DELETE_P},
- {"delimiter", DELIMITER},
- {"delimiters", DELIMITERS},
- {"desc", DESC},
- {"distinct", DISTINCT},
- {"do", DO},
- {"domain", DOMAIN_P},
- {"double", DOUBLE},
- {"drop", DROP},
- {"each", EACH},
- {"else", ELSE},
- {"encoding", ENCODING},
- {"encrypted", ENCRYPTED},
- {"end", END_TRANS},
- {"escape", ESCAPE},
- {"except", EXCEPT},
- {"exclusive", EXCLUSIVE},
- {"execute", EXECUTE},
- {"exists", EXISTS},
- {"explain", EXPLAIN},
- {"external", EXTERNAL},
- {"extract", EXTRACT},
- {"false", FALSE_P},
- {"fetch", FETCH},
- {"float", FLOAT_P},
- {"for", FOR},
- {"force", FORCE},
- {"foreign", FOREIGN},
- {"forward", FORWARD},
- {"freeze", FREEZE},
- {"from", FROM},
- {"full", FULL},
- {"function", FUNCTION},
- {"get", GET},
- {"global", GLOBAL},
- {"grant", GRANT},
- {"group", GROUP_P},
- {"handler", HANDLER},
- {"having", HAVING},
- {"hour", HOUR_P},
- {"ilike", ILIKE},
- {"immediate", IMMEDIATE},
- {"immutable", IMMUTABLE},
- {"implicit", IMPLICIT},
- {"in", IN_P},
- {"increment", INCREMENT},
- {"index", INDEX},
- {"inherits", INHERITS},
- {"initially", INITIALLY},
- {"inner", INNER_P},
- {"inout", INOUT},
- {"input", INPUT},
- {"insensitive", INSENSITIVE},
- {"insert", INSERT},
- {"instead", INSTEAD},
- {"int", INT},
- {"integer", INTEGER},
- {"intersect", INTERSECT},
- {"interval", INTERVAL},
- {"into", INTO},
- {"invoker", INVOKER},
- {"is", IS},
- {"isnull", ISNULL},
- {"isolation", ISOLATION},
- {"join", JOIN},
- {"key", KEY},
- {"lancompiler", LANCOMPILER},
- {"language", LANGUAGE},
- {"leading", LEADING},
- {"left", LEFT},
- {"level", LEVEL},
- {"like", LIKE},
- {"limit", LIMIT},
- {"listen", LISTEN},
- {"load", LOAD},
- {"local", LOCAL},
- {"localtime", LOCALTIME},
- {"localtimestamp", LOCALTIMESTAMP},
- {"location", LOCATION},
- {"lock", LOCK_P},
- {"match", MATCH},
- {"maxvalue", MAXVALUE},
- {"minute", MINUTE_P},
- {"minvalue", MINVALUE},
- {"mode", MODE},
- {"month", MONTH_P},
- {"move", MOVE},
- {"names", NAMES},
- {"national", NATIONAL},
- {"natural", NATURAL},
- {"nchar", NCHAR},
- {"new", NEW},
- {"next", NEXT},
- {"no", NO},
- {"nocreatedb", NOCREATEDB},
- {"nocreateuser", NOCREATEUSER},
- {"none", NONE},
- {"not", NOT},
- {"nothing", NOTHING},
- {"notify", NOTIFY},
- {"notnull", NOTNULL},
- {"null", NULL_P},
- {"nullif", NULLIF},
- {"numeric", NUMERIC},
- {"of", OF},
- {"off", OFF},
- {"offset", OFFSET},
- {"oids", OIDS},
- {"old", OLD},
- {"on", ON},
- {"only", ONLY},
- {"operator", OPERATOR},
- {"option", OPTION},
- {"or", OR},
- {"order", ORDER},
- {"out", OUT_P},
- {"outer", OUTER_P},
- {"overlaps", OVERLAPS},
- {"overlay", OVERLAY},
- {"owner", OWNER},
- {"partial", PARTIAL},
- {"password", PASSWORD},
- {"path", PATH_P},
- {"pendant", PENDANT},
- {"placing", PLACING},
- {"position", POSITION},
- {"precision", PRECISION},
- {"primary", PRIMARY},
- {"prior", PRIOR},
- {"privileges", PRIVILEGES},
- {"procedural", PROCEDURAL},
- {"procedure", PROCEDURE},
- {"read", READ},
- {"real", REAL},
- {"references", REFERENCES},
- {"reindex", REINDEX},
- {"relative", RELATIVE},
- {"rename", RENAME},
- {"replace", REPLACE},
- {"reset", RESET},
- {"restrict", RESTRICT},
- {"returns", RETURNS},
- {"revoke", REVOKE},
- {"right", RIGHT},
- {"rollback", ROLLBACK},
- {"row", ROW},
- {"rule", RULE},
- {"schema", SCHEMA},
- {"scroll", SCROLL},
- {"second", SECOND_P},
- {"security", SECURITY},
- {"select", SELECT},
- {"sequence", SEQUENCE},
- {"serializable", SERIALIZABLE},
- {"session", SESSION},
- {"session_user", SESSION_USER},
- {"set", SET},
- {"setof", SETOF},
- {"share", SHARE},
- {"show", SHOW},
- {"similar", SIMILAR},
- {"smallint", SMALLINT},
- {"some", SOME},
- {"stable", STABLE},
- {"start", START},
- {"statement", STATEMENT},
- {"statistics", STATISTICS},
- {"stdin", STDIN},
- {"stdout", STDOUT},
- {"storage", STORAGE},
- {"strict", STRICT},
- {"substring", SUBSTRING},
- {"sysid", SYSID},
- {"table", TABLE},
- {"temp", TEMP},
- {"template", TEMPLATE},
- {"temporary", TEMPORARY},
- {"then", THEN},
- {"time", TIME},
- {"timestamp", TIMESTAMP},
- {"to", TO},
- {"toast", TOAST},
- {"trailing", TRAILING},
- {"transaction", TRANSACTION},
- {"trigger", TRIGGER},
- {"trim", TRIM},
- {"true", TRUE_P},
- {"truncate", TRUNCATE},
- {"trusted", TRUSTED},
- {"type", TYPE_P},
- {"unencrypted", UNENCRYPTED},
- {"union", UNION},
- {"unique", UNIQUE},
- {"unknown", UNKNOWN},
- {"unlisten", UNLISTEN},
- {"until", UNTIL},
- {"update", UPDATE},
- {"usage", USAGE},
- {"user", USER},
- {"using", USING},
- {"vacuum", VACUUM},
- {"valid", VALID},
- {"validator", VALIDATOR},
- {"values", VALUES},
- {"varchar", VARCHAR},
- {"varying", VARYING},
- {"verbose", VERBOSE},
- {"version", VERSION},
- {"view", VIEW},
- {"volatile", VOLATILE},
- {"when", WHEN},
- {"where", WHERE},
- {"with", WITH},
- {"without", WITHOUT},
- {"work", WORK},
- {"year", YEAR_P},
- {"zone", ZONE},
-};
-
-/*
- * ScanKeywordLookup - see if a given word is a keyword
- *
- * Returns a pointer to the ScanKeyword table entry, or NULL if no match.
- *
- * The match is done case-insensitively. Note that we deliberately use a
- * dumbed-down case conversion that will only translate 'A'-'Z' into 'a'-'z',
- * even if we are in a locale where tolower() would produce more or different
- * translations. This is to conform to the SQL99 spec, which says that
- * keywords are to be matched in this way even though non-keyword identifiers
- * receive a different case-normalization mapping.
- */
-const ScanKeyword *
-ScanKeywordLookup(const char *text)
-{
- int len,
- i;
- char word[NAMEDATALEN];
- const ScanKeyword *low;
- const ScanKeyword *high;
-
- len = strlen(text);
- /* We assume all keywords are shorter than NAMEDATALEN. */
- if (len >= NAMEDATALEN)
- return NULL;
-
- /*
- * Apply an ASCII-only downcasing. We must not use tolower() since it
- * may produce the wrong translation in some locales (eg, Turkish),
- * and we don't trust isupper() very much either. In an ASCII-based
- * encoding the tests against A and Z are sufficient, but we also
- * check isupper() so that we will work correctly under EBCDIC. The
- * actual case conversion step should work for either ASCII or EBCDIC.
- */
- for (i = 0; i < len; i++)
- {
- char ch = text[i];
-
- if (ch >= 'A' && ch <= 'Z' && isupper((unsigned char) ch))
- ch += 'a' - 'A';
- word[i] = ch;
- }
- word[len] = '\0';
-
- /*
- * Now do a binary search using plain strcmp() comparison.
- */
- low = &ScanKeywords[0];
- high = endof(ScanKeywords) - 1;
- while (low <= high)
- {
- const ScanKeyword *middle;
- int difference;
-
- middle = low + (high - low) / 2;
- difference = strcmp(middle->name, word);
- if (difference == 0)
- return middle;
- else if (difference < 0)
- low = middle + 1;
- else
- high = middle - 1;
- }
-
- return NULL;
-}
diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c
deleted file mode 100644
index 127abdc2de8..00000000000
--- a/src/backend/parser/parse_agg.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_agg.c
- * handle aggregates in parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.50 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "optimizer/clauses.h"
-#include "optimizer/tlist.h"
-#include "parser/parse_agg.h"
-#include "parser/parsetree.h"
-
-
-typedef struct
-{
- ParseState *pstate;
- List *groupClauses;
-} check_ungrouped_columns_context;
-
-static void check_ungrouped_columns(Node *node, ParseState *pstate,
- List *groupClauses);
-static bool check_ungrouped_columns_walker(Node *node,
- check_ungrouped_columns_context *context);
-
-/*
- * check_ungrouped_columns -
- * Scan the given expression tree for ungrouped variables (variables
- * that are not listed in the groupClauses list and are not within
- * the arguments of aggregate functions). Emit a suitable error message
- * if any are found.
- *
- * NOTE: we assume that the given clause has been transformed suitably for
- * parser output. This means we can use the planner's expression_tree_walker.
- *
- * NOTE: in the case of a SubLink, expression_tree_walker does not descend
- * into the subquery. This means we will fail to detect ungrouped columns
- * that appear as outer-level variables within a subquery. That case seems
- * unreasonably hard to handle here. Instead, we expect the planner to check
- * for ungrouped columns after it's found all the outer-level references
- * inside the subquery and converted them into a list of parameters for the
- * subquery.
- */
-static void
-check_ungrouped_columns(Node *node, ParseState *pstate,
- List *groupClauses)
-{
- check_ungrouped_columns_context context;
-
- context.pstate = pstate;
- context.groupClauses = groupClauses;
- check_ungrouped_columns_walker(node, &context);
-}
-
-static bool
-check_ungrouped_columns_walker(Node *node,
- check_ungrouped_columns_context *context)
-{
- List *gl;
-
- if (node == NULL)
- return false;
- if (IsA(node, Const) ||IsA(node, Param))
- return false; /* constants are always acceptable */
-
- /*
- * If we find an aggregate function, do not recurse into its
- * arguments.
- */
- if (IsA(node, Aggref))
- return false;
-
- /*
- * Check to see if subexpression as a whole matches any GROUP BY item.
- * We need to do this at every recursion level so that we recognize
- * GROUPed-BY expressions before reaching variables within them.
- */
- foreach(gl, context->groupClauses)
- {
- if (equal(node, lfirst(gl)))
- return false; /* acceptable, do not descend more */
- }
-
- /*
- * If we have an ungrouped Var, we have a failure --- unless it is an
- * outer-level Var. In that case it's a constant as far as this query
- * level is concerned, and we can accept it. (If it's ungrouped as
- * far as the upper query is concerned, that's someone else's
- * problem...)
- */
- if (IsA(node, Var))
- {
- Var *var = (Var *) node;
- RangeTblEntry *rte;
- char *attname;
-
- if (var->varlevelsup > 0)
- return false; /* outer-level Var is acceptable */
- /* Found an ungrouped local variable; generate error message */
- Assert(var->varno > 0 &&
- (int) var->varno <= length(context->pstate->p_rtable));
- rte = rt_fetch(var->varno, context->pstate->p_rtable);
- attname = get_rte_attribute_name(rte, var->varattno);
- elog(ERROR, "Attribute %s.%s must be GROUPed or used in an aggregate function",
- rte->eref->aliasname, attname);
- }
- /* Otherwise, recurse. */
- return expression_tree_walker(node, check_ungrouped_columns_walker,
- (void *) context);
-}
-
-/*
- * parseCheckAggregates
- * Check for aggregates where they shouldn't be and improper grouping.
- *
- * Ideally this should be done earlier, but it's difficult to distinguish
- * aggregates from plain functions at the grammar level. So instead we
- * check here. This function should be called after the target list and
- * qualifications are finalized. BUT: in some cases we want to call this
- * routine before we've assembled the joinlist and qual into a FromExpr.
- * So, rather than looking at qry->jointree, look at pstate->p_joinlist
- * and the explicitly-passed qual.
- */
-void
-parseCheckAggregates(ParseState *pstate, Query *qry, Node *qual)
-{
- List *groupClauses = NIL;
- List *tl;
-
- /* This should only be called if we found aggregates, GROUP, or HAVING */
- Assert(pstate->p_hasAggs || qry->groupClause || qry->havingQual);
-
- /*
- * Aggregates must never appear in WHERE or JOIN/ON clauses.
- *
- * (Note this check should appear first to deliver an appropriate error
- * message; otherwise we are likely to complain about some innocent
- * variable in the target list, which is outright misleading if the
- * problem is in WHERE.)
- */
- if (contain_agg_clause(qual))
- elog(ERROR, "Aggregates not allowed in WHERE clause");
- if (contain_agg_clause((Node *) pstate->p_joinlist))
- elog(ERROR, "Aggregates not allowed in JOIN conditions");
-
- /*
- * No aggregates allowed in GROUP BY clauses, either.
- *
- * While we are at it, build a list of the acceptable GROUP BY
- * expressions for use by check_ungrouped_columns() (this avoids
- * repeated scans of the targetlist within the recursive routine...)
- */
- foreach(tl, qry->groupClause)
- {
- GroupClause *grpcl = lfirst(tl);
- Node *expr;
-
- expr = get_sortgroupclause_expr(grpcl, qry->targetList);
- if (contain_agg_clause(expr))
- elog(ERROR, "Aggregates not allowed in GROUP BY clause");
- groupClauses = lcons(expr, groupClauses);
- }
-
- /*
- * Check the targetlist and HAVING clause for ungrouped variables.
- */
- check_ungrouped_columns((Node *) qry->targetList, pstate, groupClauses);
- check_ungrouped_columns((Node *) qry->havingQual, pstate, groupClauses);
-
- /* Release the list storage (but not the pointed-to expressions!) */
- freeList(groupClauses);
-}
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
deleted file mode 100644
index 81328798eb5..00000000000
--- a/src/backend/parser/parse_clause.c
+++ /dev/null
@@ -1,1405 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_clause.c
- * handle clauses in parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.94 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "access/heapam.h"
-#include "nodes/makefuncs.h"
-#include "optimizer/clauses.h"
-#include "optimizer/tlist.h"
-#include "optimizer/var.h"
-#include "parser/analyze.h"
-#include "parser/parse.h"
-#include "parser/parsetree.h"
-#include "parser/parse_clause.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_oper.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_target.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/guc.h"
-
-
-#define ORDER_CLAUSE 0
-#define GROUP_CLAUSE 1
-#define DISTINCT_ON_CLAUSE 2
-
-static char *clauseText[] = {"ORDER BY", "GROUP BY", "DISTINCT ON"};
-
-static void extractRemainingColumns(List *common_colnames,
- List *src_colnames, List *src_colvars,
- List **res_colnames, List **res_colvars);
-static Node *transformJoinUsingClause(ParseState *pstate,
- List *leftVars, List *rightVars);
-static Node *transformJoinOnClause(ParseState *pstate, JoinExpr *j,
- List *containedRels);
-static RangeTblRef *transformTableEntry(ParseState *pstate, RangeVar *r);
-static RangeTblRef *transformRangeSubselect(ParseState *pstate,
- RangeSubselect *r);
-static RangeTblRef *transformRangeFunction(ParseState *pstate,
- RangeFunction *r);
-static Node *transformFromClauseItem(ParseState *pstate, Node *n,
- List **containedRels);
-static Node *buildMergedJoinVar(JoinType jointype,
- Var *l_colvar, Var *r_colvar);
-static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node,
- List *tlist, int clause);
-static List *addTargetToSortList(TargetEntry *tle, List *sortlist,
- List *targetlist, List *opname);
-static bool exprIsInSortList(Node *expr, List *sortList, List *targetList);
-
-
-/*
- * transformFromClause -
- * Process the FROM clause and add items to the query's range table,
- * joinlist, and namespace.
- *
- * Note: we assume that pstate's p_rtable, p_joinlist, and p_namespace lists
- * were initialized to NIL when the pstate was created. We will add onto
- * any entries already present --- this is needed for rule processing, as
- * well as for UPDATE and DELETE.
- *
- * The range table may grow still further when we transform the expressions
- * in the query's quals and target list. (This is possible because in
- * POSTQUEL, we allowed references to relations not specified in the
- * from-clause. PostgreSQL keeps this extension to standard SQL.)
- */
-void
-transformFromClause(ParseState *pstate, List *frmList)
-{
- List *fl;
-
- /*
- * The grammar will have produced a list of RangeVars,
- * RangeSubselects, RangeFunctions, and/or JoinExprs. Transform each one
- * (possibly adding entries to the rtable), check for duplicate refnames,
- * and then add it to the joinlist and namespace.
- */
- foreach(fl, frmList)
- {
- Node *n = lfirst(fl);
- List *containedRels;
-
- n = transformFromClauseItem(pstate, n, &containedRels);
- checkNameSpaceConflicts(pstate, (Node *) pstate->p_namespace, n);
- pstate->p_joinlist = lappend(pstate->p_joinlist, n);
- pstate->p_namespace = lappend(pstate->p_namespace, n);
- }
-}
-
-/*
- * setTargetTable
- * Add the target relation of INSERT/UPDATE/DELETE to the range table,
- * and make the special links to it in the ParseState.
- *
- * We also open the target relation and acquire a write lock on it.
- * This must be done before processing the FROM list, in case the target
- * is also mentioned as a source relation --- we want to be sure to grab
- * the write lock before any read lock.
- *
- * If alsoSource is true, add the target to the query's joinlist and
- * namespace. For INSERT, we don't want the target to be joined to;
- * it's a destination of tuples, not a source. For UPDATE/DELETE,
- * we do need to scan or join the target. (NOTE: we do not bother
- * to check for namespace conflict; we assume that the namespace was
- * initially empty in these cases.)
- *
- * Returns the rangetable index of the target relation.
- */
-int
-setTargetTable(ParseState *pstate, RangeVar *relation,
- bool inh, bool alsoSource)
-{
- RangeTblEntry *rte;
- int rtindex;
-
- /* Close old target; this could only happen for multi-action rules */
- if (pstate->p_target_relation != NULL)
- heap_close(pstate->p_target_relation, NoLock);
-
- /*
- * Open target rel and grab suitable lock (which we will hold till end
- * of transaction).
- *
- * analyze.c will eventually do the corresponding heap_close(), but *not*
- * release the lock.
- */
- pstate->p_target_relation = heap_openrv(relation, RowExclusiveLock);
-
- /*
- * Now build an RTE.
- */
- rte = addRangeTableEntry(pstate, relation, NULL, inh, false);
- pstate->p_target_rangetblentry = rte;
-
- /* assume new rte is at end */
- rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtindex, pstate->p_rtable));
-
- /*
- * Override addRangeTableEntry's default checkForRead, and instead
- * mark target table as requiring write access.
- *
- * If we find an explicit reference to the rel later during parse
- * analysis, scanRTEForColumn will change checkForRead to 'true'
- * again. That can't happen for INSERT but it is possible for UPDATE
- * and DELETE.
- */
- rte->checkForRead = false;
- rte->checkForWrite = true;
-
- /*
- * If UPDATE/DELETE, add table to joinlist and namespace.
- */
- if (alsoSource)
- addRTEtoQuery(pstate, rte, true, true);
-
- return rtindex;
-}
-
-/*
- * Simplify InhOption (yes/no/default) into boolean yes/no.
- *
- * The reason we do things this way is that we don't want to examine the
- * SQL_inheritance option flag until parse_analyze is run. Otherwise,
- * we'd do the wrong thing with query strings that intermix SET commands
- * with queries.
- */
-bool
-interpretInhOption(InhOption inhOpt)
-{
- switch (inhOpt)
- {
- case INH_NO:
- return false;
- case INH_YES:
- return true;
- case INH_DEFAULT:
- return SQL_inheritance;
- }
- elog(ERROR, "Bogus InhOption value");
- return false; /* keep compiler quiet */
-}
-
-/*
- * Extract all not-in-common columns from column lists of a source table
- */
-static void
-extractRemainingColumns(List *common_colnames,
- List *src_colnames, List *src_colvars,
- List **res_colnames, List **res_colvars)
-{
- List *new_colnames = NIL;
- List *new_colvars = NIL;
- List *lnames,
- *lvars = src_colvars;
-
- foreach(lnames, src_colnames)
- {
- char *colname = strVal(lfirst(lnames));
- bool match = false;
- List *cnames;
-
- foreach(cnames, common_colnames)
- {
- char *ccolname = strVal(lfirst(cnames));
-
- if (strcmp(colname, ccolname) == 0)
- {
- match = true;
- break;
- }
- }
-
- if (!match)
- {
- new_colnames = lappend(new_colnames, lfirst(lnames));
- new_colvars = lappend(new_colvars, lfirst(lvars));
- }
-
- lvars = lnext(lvars);
- }
-
- *res_colnames = new_colnames;
- *res_colvars = new_colvars;
-}
-
-/* transformJoinUsingClause()
- * Build a complete ON clause from a partially-transformed USING list.
- * We are given lists of nodes representing left and right match columns.
- * Result is a transformed qualification expression.
- */
-static Node *
-transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars)
-{
- Node *result = NULL;
- List *lvars,
- *rvars = rightVars;
-
- /*
- * We cheat a little bit here by building an untransformed operator
- * tree whose leaves are the already-transformed Vars. This is OK
- * because transformExpr() won't complain about already-transformed
- * subnodes.
- */
- foreach(lvars, leftVars)
- {
- Node *lvar = (Node *) lfirst(lvars);
- Node *rvar = (Node *) lfirst(rvars);
- A_Expr *e;
-
- e = makeSimpleA_Expr(OP, "=", copyObject(lvar), copyObject(rvar));
-
- if (result == NULL)
- result = (Node *) e;
- else
- {
- A_Expr *a;
-
- a = makeA_Expr(AND, NIL, result, (Node *) e);
- result = (Node *) a;
- }
-
- rvars = lnext(rvars);
- }
-
- /*
- * Since the references are already Vars, and are certainly from the
- * input relations, we don't have to go through the same pushups that
- * transformJoinOnClause() does. Just invoke transformExpr() to fix
- * up the operators, and we're done.
- */
- result = transformExpr(pstate, result);
-
- result = coerce_to_boolean(result, "JOIN/USING");
-
- return result;
-} /* transformJoinUsingClause() */
-
-/* transformJoinOnClause()
- * Transform the qual conditions for JOIN/ON.
- * Result is a transformed qualification expression.
- */
-static Node *
-transformJoinOnClause(ParseState *pstate, JoinExpr *j,
- List *containedRels)
-{
- Node *result;
- List *save_namespace;
- List *clause_varnos,
- *l;
-
- /*
- * This is a tad tricky, for two reasons. First, the namespace that
- * the join expression should see is just the two subtrees of the JOIN
- * plus any outer references from upper pstate levels. So,
- * temporarily set this pstate's namespace accordingly. (We need not
- * check for refname conflicts, because transformFromClauseItem()
- * already did.) NOTE: this code is OK only because the ON clause
- * can't legally alter the namespace by causing implicit relation refs
- * to be added.
- */
- save_namespace = pstate->p_namespace;
- pstate->p_namespace = makeList2(j->larg, j->rarg);
-
- /* This part is just like transformWhereClause() */
- result = transformExpr(pstate, j->quals);
-
- result = coerce_to_boolean(result, "JOIN/ON");
-
- pstate->p_namespace = save_namespace;
-
- /*
- * Second, we need to check that the ON condition doesn't refer to any
- * rels outside the input subtrees of the JOIN. It could do that
- * despite our hack on the namespace if it uses fully-qualified names.
- * So, grovel through the transformed clause and make sure there are
- * no bogus references. (Outer references are OK, and are ignored
- * here.)
- */
- clause_varnos = pull_varnos(result);
- foreach(l, clause_varnos)
- {
- int varno = lfirsti(l);
-
- if (!intMember(varno, containedRels))
- {
- elog(ERROR, "JOIN/ON clause refers to \"%s\", which is not part of JOIN",
- rt_fetch(varno, pstate->p_rtable)->eref->aliasname);
- }
- }
- freeList(clause_varnos);
-
- return result;
-}
-
-/*
- * transformTableEntry --- transform a RangeVar (simple relation reference)
- */
-static RangeTblRef *
-transformTableEntry(ParseState *pstate, RangeVar *r)
-{
- RangeTblEntry *rte;
- RangeTblRef *rtr;
-
- /*
- * mark this entry to indicate it comes from the FROM clause. In SQL,
- * the target list can only refer to range variables specified in the
- * from clause but we follow the more powerful POSTQUEL semantics and
- * automatically generate the range variable if not specified. However
- * there are times we need to know whether the entries are legitimate.
- */
- rte = addRangeTableEntry(pstate, r, r->alias,
- interpretInhOption(r->inhOpt), true);
-
- /*
- * We create a RangeTblRef, but we do not add it to the joinlist or
- * namespace; our caller must do that if appropriate.
- */
- rtr = makeNode(RangeTblRef);
- /* assume new rte is at end */
- rtr->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtr->rtindex, pstate->p_rtable));
-
- return rtr;
-}
-
-
-/*
- * transformRangeSubselect --- transform a sub-SELECT appearing in FROM
- */
-static RangeTblRef *
-transformRangeSubselect(ParseState *pstate, RangeSubselect *r)
-{
- List *save_namespace;
- List *parsetrees;
- Query *query;
- RangeTblEntry *rte;
- RangeTblRef *rtr;
-
- /*
- * We require user to supply an alias for a subselect, per SQL92. To
- * relax this, we'd have to be prepared to gin up a unique alias for
- * an unlabeled subselect.
- */
- if (r->alias == NULL)
- elog(ERROR, "sub-select in FROM must have an alias");
-
- /*
- * Analyze and transform the subquery. This is a bit tricky because
- * we don't want the subquery to be able to see any FROM items already
- * created in the current query (per SQL92, the scope of a FROM item
- * does not include other FROM items). But it does need to be able to
- * see any further-up parent states, so we can't just pass a null
- * parent pstate link. So, temporarily make the current query level
- * have an empty namespace.
- */
- save_namespace = pstate->p_namespace;
- pstate->p_namespace = NIL;
-
- parsetrees = parse_analyze(r->subquery, pstate);
-
- pstate->p_namespace = save_namespace;
-
- /*
- * Check that we got something reasonable. Some of these conditions
- * are probably impossible given restrictions of the grammar, but
- * check 'em anyway.
- */
- if (length(parsetrees) != 1)
- elog(ERROR, "Unexpected parse analysis result for subselect in FROM");
- query = (Query *) lfirst(parsetrees);
- if (query == NULL || !IsA(query, Query))
- elog(ERROR, "Unexpected parse analysis result for subselect in FROM");
-
- if (query->commandType != CMD_SELECT)
- elog(ERROR, "Expected SELECT query from subselect in FROM");
- if (query->resultRelation != 0 || query->into != NULL || query->isPortal)
- elog(ERROR, "Subselect in FROM may not have SELECT INTO");
-
- /*
- * OK, build an RTE for the subquery.
- */
- rte = addRangeTableEntryForSubquery(pstate, query, r->alias, true);
-
- /*
- * We create a RangeTblRef, but we do not add it to the joinlist or
- * namespace; our caller must do that if appropriate.
- */
- rtr = makeNode(RangeTblRef);
- /* assume new rte is at end */
- rtr->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtr->rtindex, pstate->p_rtable));
-
- return rtr;
-}
-
-
-/*
- * transformRangeFunction --- transform a function call appearing in FROM
- */
-static RangeTblRef *
-transformRangeFunction(ParseState *pstate, RangeFunction *r)
-{
- Node *funcexpr;
- char *funcname;
- List *save_namespace;
- RangeTblEntry *rte;
- RangeTblRef *rtr;
-
- /* Get function name for possible use as alias */
- Assert(IsA(r->funccallnode, FuncCall));
- funcname = strVal(llast(((FuncCall *) r->funccallnode)->funcname));
-
- /*
- * Transform the raw FuncCall node. This is a bit tricky because we don't
- * want the function expression to be able to see any FROM items already
- * created in the current query (compare to transformRangeSubselect).
- * But it does need to be able to see any further-up parent states.
- * So, temporarily make the current query level have an empty namespace.
- * NOTE: this code is OK only because the expression can't legally alter
- * the namespace by causing implicit relation refs to be added.
- */
- save_namespace = pstate->p_namespace;
- pstate->p_namespace = NIL;
-
- funcexpr = transformExpr(pstate, r->funccallnode);
-
- pstate->p_namespace = save_namespace;
-
- /*
- * We still need to check that the function parameters don't refer
- * to any other rels. That could happen despite our hack on the namespace
- * if fully-qualified names are used. So, check there are no local
- * Var references in the transformed expression. (Outer references
- * are OK, and are ignored here.)
- */
- if (pull_varnos(funcexpr) != NIL)
- elog(ERROR, "FROM function expression may not refer to other relations of same query level");
-
- /*
- * Disallow aggregate functions in the expression. (No reason to postpone
- * this check until parseCheckAggregates.)
- */
- if (pstate->p_hasAggs)
- {
- if (contain_agg_clause(funcexpr))
- elog(ERROR, "cannot use aggregate function in FROM function expression");
- }
-
- /*
- * Insist we have a bare function call (explain.c is the only place
- * that depends on this, I think). If this fails, it's probably because
- * transformExpr interpreted the function notation as a type coercion.
- */
- if (!funcexpr ||
- !IsA(funcexpr, Expr) ||
- ((Expr *) funcexpr)->opType != FUNC_EXPR)
- elog(ERROR, "Coercion function not allowed in FROM clause");
-
- /*
- * OK, build an RTE for the function.
- */
- rte = addRangeTableEntryForFunction(pstate, funcname, funcexpr,
- r->alias, true);
-
- /*
- * We create a RangeTblRef, but we do not add it to the joinlist or
- * namespace; our caller must do that if appropriate.
- */
- rtr = makeNode(RangeTblRef);
- /* assume new rte is at end */
- rtr->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(rtr->rtindex, pstate->p_rtable));
-
- return rtr;
-}
-
-
-/*
- * transformFromClauseItem -
- * Transform a FROM-clause item, adding any required entries to the
- * range table list being built in the ParseState, and return the
- * transformed item ready to include in the joinlist and namespace.
- * This routine can recurse to handle SQL92 JOIN expressions.
- *
- * Aside from the primary return value (the transformed joinlist item)
- * this routine also returns an integer list of the rangetable indexes
- * of all the base and join relations represented in the joinlist item.
- * This list is needed for checking JOIN/ON conditions in higher levels.
- */
-static Node *
-transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
-{
- if (IsA(n, RangeVar))
- {
- /* Plain relation reference */
- RangeTblRef *rtr;
-
- rtr = transformTableEntry(pstate, (RangeVar *) n);
- *containedRels = makeListi1(rtr->rtindex);
- return (Node *) rtr;
- }
- else if (IsA(n, RangeSubselect))
- {
- /* sub-SELECT is like a plain relation */
- RangeTblRef *rtr;
-
- rtr = transformRangeSubselect(pstate, (RangeSubselect *) n);
- *containedRels = makeListi1(rtr->rtindex);
- return (Node *) rtr;
- }
- else if (IsA(n, RangeFunction))
- {
- /* function is like a plain relation */
- RangeTblRef *rtr;
-
- rtr = transformRangeFunction(pstate, (RangeFunction *) n);
- *containedRels = makeListi1(rtr->rtindex);
- return (Node *) rtr;
- }
- else if (IsA(n, JoinExpr))
- {
- /* A newfangled join expression */
- JoinExpr *j = (JoinExpr *) n;
- List *my_containedRels,
- *l_containedRels,
- *r_containedRels,
- *l_colnames,
- *r_colnames,
- *res_colnames,
- *l_colvars,
- *r_colvars,
- *res_colvars;
- Index leftrti,
- rightrti;
- RangeTblEntry *rte;
-
- /*
- * Recursively process the left and right subtrees
- */
- j->larg = transformFromClauseItem(pstate, j->larg, &l_containedRels);
- j->rarg = transformFromClauseItem(pstate, j->rarg, &r_containedRels);
-
- /*
- * Generate combined list of relation indexes for possible use
- * by transformJoinOnClause below.
- */
- my_containedRels = nconc(l_containedRels, r_containedRels);
-
- /*
- * Check for conflicting refnames in left and right subtrees. Must
- * do this because higher levels will assume I hand back a self-
- * consistent namespace subtree.
- */
- checkNameSpaceConflicts(pstate, j->larg, j->rarg);
-
- /*
- * Extract column name and var lists from both subtrees
- *
- * Note: expandRTE returns new lists, safe for me to modify
- */
- if (IsA(j->larg, RangeTblRef))
- leftrti = ((RangeTblRef *) j->larg)->rtindex;
- else if (IsA(j->larg, JoinExpr))
- leftrti = ((JoinExpr *) j->larg)->rtindex;
- else
- {
- elog(ERROR, "transformFromClauseItem: unexpected subtree type");
- leftrti = 0; /* keep compiler quiet */
- }
- rte = rt_fetch(leftrti, pstate->p_rtable);
- expandRTE(pstate, rte, &l_colnames, &l_colvars);
-
- if (IsA(j->rarg, RangeTblRef))
- rightrti = ((RangeTblRef *) j->rarg)->rtindex;
- else if (IsA(j->rarg, JoinExpr))
- rightrti = ((JoinExpr *) j->rarg)->rtindex;
- else
- {
- elog(ERROR, "transformFromClauseItem: unexpected subtree type");
- rightrti = 0; /* keep compiler quiet */
- }
- rte = rt_fetch(rightrti, pstate->p_rtable);
- expandRTE(pstate, rte, &r_colnames, &r_colvars);
-
- /*
- * Natural join does not explicitly specify columns; must generate
- * columns to join. Need to run through the list of columns from
- * each table or join result and match up the column names. Use
- * the first table, and check every column in the second table for
- * a match. (We'll check that the matches were unique later on.)
- * The result of this step is a list of column names just like an
- * explicitly-written USING list.
- */
- if (j->isNatural)
- {
- List *rlist = NIL;
- List *lx,
- *rx;
-
- Assert(j->using == NIL); /* shouldn't have USING() too */
-
- foreach(lx, l_colnames)
- {
- char *l_colname = strVal(lfirst(lx));
- Value *m_name = NULL;
-
- foreach(rx, r_colnames)
- {
- char *r_colname = strVal(lfirst(rx));
-
- if (strcmp(l_colname, r_colname) == 0)
- {
- m_name = makeString(l_colname);
- break;
- }
- }
-
- /* matched a right column? then keep as join column... */
- if (m_name != NULL)
- rlist = lappend(rlist, m_name);
- }
-
- j->using = rlist;
- }
-
- /*
- * Now transform the join qualifications, if any.
- */
- res_colnames = NIL;
- res_colvars = NIL;
-
- if (j->using)
- {
- /*
- * JOIN/USING (or NATURAL JOIN, as transformed above).
- * Transform the list into an explicit ON-condition, and
- * generate a list of merged result columns.
- */
- List *ucols = j->using;
- List *l_usingvars = NIL;
- List *r_usingvars = NIL;
- List *ucol;
-
- Assert(j->quals == NULL); /* shouldn't have ON() too */
-
- foreach(ucol, ucols)
- {
- char *u_colname = strVal(lfirst(ucol));
- List *col;
- int ndx;
- int l_index = -1;
- int r_index = -1;
- Var *l_colvar,
- *r_colvar;
-
- /* Check for USING(foo,foo) */
- foreach(col, res_colnames)
- {
- char *res_colname = strVal(lfirst(col));
-
- if (strcmp(res_colname, u_colname) == 0)
- elog(ERROR, "USING column name \"%s\" appears more than once", u_colname);
- }
-
- /* Find it in left input */
- ndx = 0;
- foreach(col, l_colnames)
- {
- char *l_colname = strVal(lfirst(col));
-
- if (strcmp(l_colname, u_colname) == 0)
- {
- if (l_index >= 0)
- elog(ERROR, "Common column name \"%s\" appears more than once in left table", u_colname);
- l_index = ndx;
- }
- ndx++;
- }
- if (l_index < 0)
- elog(ERROR, "JOIN/USING column \"%s\" not found in left table",
- u_colname);
-
- /* Find it in right input */
- ndx = 0;
- foreach(col, r_colnames)
- {
- char *r_colname = strVal(lfirst(col));
-
- if (strcmp(r_colname, u_colname) == 0)
- {
- if (r_index >= 0)
- elog(ERROR, "Common column name \"%s\" appears more than once in right table", u_colname);
- r_index = ndx;
- }
- ndx++;
- }
- if (r_index < 0)
- elog(ERROR, "JOIN/USING column \"%s\" not found in right table",
- u_colname);
-
- l_colvar = nth(l_index, l_colvars);
- l_usingvars = lappend(l_usingvars, l_colvar);
- r_colvar = nth(r_index, r_colvars);
- r_usingvars = lappend(r_usingvars, r_colvar);
-
- res_colnames = lappend(res_colnames, lfirst(ucol));
- res_colvars = lappend(res_colvars,
- buildMergedJoinVar(j->jointype,
- l_colvar,
- r_colvar));
- }
-
- j->quals = transformJoinUsingClause(pstate,
- l_usingvars,
- r_usingvars);
- }
- else if (j->quals)
- {
- /* User-written ON-condition; transform it */
- j->quals = transformJoinOnClause(pstate, j, my_containedRels);
- }
- else
- {
- /* CROSS JOIN: no quals */
- }
-
- /* Add remaining columns from each side to the output columns */
- extractRemainingColumns(res_colnames,
- l_colnames, l_colvars,
- &l_colnames, &l_colvars);
- extractRemainingColumns(res_colnames,
- r_colnames, r_colvars,
- &r_colnames, &r_colvars);
- res_colnames = nconc(res_colnames, l_colnames);
- res_colvars = nconc(res_colvars, l_colvars);
- res_colnames = nconc(res_colnames, r_colnames);
- res_colvars = nconc(res_colvars, r_colvars);
-
- /*
- * Check alias (AS clause), if any.
- */
- if (j->alias)
- {
- if (j->alias->colnames != NIL)
- {
- if (length(j->alias->colnames) > length(res_colnames))
- elog(ERROR, "Column alias list for \"%s\" has too many entries",
- j->alias->aliasname);
- }
- }
-
- /*
- * Now build an RTE for the result of the join
- */
- rte = addRangeTableEntryForJoin(pstate,
- res_colnames,
- j->jointype,
- res_colvars,
- j->alias,
- true);
-
- /* assume new rte is at end */
- j->rtindex = length(pstate->p_rtable);
- Assert(rte == rt_fetch(j->rtindex, pstate->p_rtable));
-
- /*
- * Include join RTE in returned containedRels list
- */
- *containedRels = lconsi(j->rtindex, my_containedRels);
-
- return (Node *) j;
- }
- else
- elog(ERROR, "transformFromClauseItem: unexpected node (internal error)"
- "\n\t%s", nodeToString(n));
- return NULL; /* can't get here, just keep compiler
- * quiet */
-}
-
-/*
- * buildMergedJoinVar -
- * generate a suitable replacement expression for a merged join column
- */
-static Node *
-buildMergedJoinVar(JoinType jointype, Var *l_colvar, Var *r_colvar)
-{
- Oid outcoltype;
- int32 outcoltypmod;
- Node *l_node,
- *r_node,
- *res_node;
-
- /*
- * Choose output type if input types are dissimilar.
- */
- outcoltype = l_colvar->vartype;
- outcoltypmod = l_colvar->vartypmod;
- if (outcoltype != r_colvar->vartype)
- {
- outcoltype = select_common_type(makeListi2(l_colvar->vartype,
- r_colvar->vartype),
- "JOIN/USING");
- outcoltypmod = -1; /* ie, unknown */
- }
- else if (outcoltypmod != r_colvar->vartypmod)
- {
- /* same type, but not same typmod */
- outcoltypmod = -1; /* ie, unknown */
- }
-
- /*
- * Insert coercion functions if needed. Note that a difference in
- * typmod can only happen if input has typmod but outcoltypmod is -1.
- * In that case we insert a RelabelType to clearly mark that result's
- * typmod is not same as input.
- */
- if (l_colvar->vartype != outcoltype)
- l_node = coerce_type(NULL, (Node *) l_colvar, l_colvar->vartype,
- outcoltype, outcoltypmod, false);
- else if (l_colvar->vartypmod != outcoltypmod)
- l_node = (Node *) makeRelabelType((Node *) l_colvar,
- outcoltype, outcoltypmod);
- else
- l_node = (Node *) l_colvar;
-
- if (r_colvar->vartype != outcoltype)
- r_node = coerce_type(NULL, (Node *) r_colvar, r_colvar->vartype,
- outcoltype, outcoltypmod, false);
- else if (r_colvar->vartypmod != outcoltypmod)
- r_node = (Node *) makeRelabelType((Node *) r_colvar,
- outcoltype, outcoltypmod);
- else
- r_node = (Node *) r_colvar;
-
- /*
- * Choose what to emit
- */
- switch (jointype)
- {
- case JOIN_INNER:
- /*
- * We can use either var; prefer non-coerced one if available.
- */
- if (IsA(l_node, Var))
- res_node = l_node;
- else if (IsA(r_node, Var))
- res_node = r_node;
- else
- res_node = l_node;
- break;
- case JOIN_LEFT:
- /* Always use left var */
- res_node = l_node;
- break;
- case JOIN_RIGHT:
- /* Always use right var */
- res_node = r_node;
- break;
- case JOIN_FULL:
- {
- /*
- * Here we must build a COALESCE expression to ensure that
- * the join output is non-null if either input is.
- */
- CaseExpr *c = makeNode(CaseExpr);
- CaseWhen *w = makeNode(CaseWhen);
- NullTest *n = makeNode(NullTest);
-
- n->arg = l_node;
- n->nulltesttype = IS_NOT_NULL;
- w->expr = (Node *) n;
- w->result = l_node;
- c->casetype = outcoltype;
- c->args = makeList1(w);
- c->defresult = r_node;
- res_node = (Node *) c;
- break;
- }
- default:
- elog(ERROR, "buildMergedJoinVar: unexpected jointype %d",
- (int) jointype);
- res_node = NULL; /* keep compiler quiet */
- break;
- }
-
- return res_node;
-}
-
-
-/*
- * transformWhereClause -
- * transforms the qualification and make sure it is of type Boolean
- */
-Node *
-transformWhereClause(ParseState *pstate, Node *clause)
-{
- Node *qual;
-
- if (clause == NULL)
- return NULL;
-
- qual = transformExpr(pstate, clause);
-
- qual = coerce_to_boolean(qual, "WHERE");
-
- return qual;
-}
-
-
-/*
- * findTargetlistEntry -
- * Returns the targetlist entry matching the given (untransformed) node.
- * If no matching entry exists, one is created and appended to the target
- * list as a "resjunk" node.
- *
- * node the ORDER BY, GROUP BY, or DISTINCT ON expression to be matched
- * tlist the existing target list (NB: this will never be NIL, which is a
- * good thing since we'd be unable to append to it if it were...)
- * clause identifies clause type being processed.
- */
-static TargetEntry *
-findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
-{
- TargetEntry *target_result = NULL;
- List *tl;
- Node *expr;
-
- /*----------
- * Handle two special cases as mandated by the SQL92 spec:
- *
- * 1. Bare ColumnName (no qualifier or subscripts)
- * For a bare identifier, we search for a matching column name
- * in the existing target list. Multiple matches are an error
- * unless they refer to identical values; for example,
- * we allow SELECT a, a FROM table ORDER BY a
- * but not SELECT a AS b, b FROM table ORDER BY b
- * If no match is found, we fall through and treat the identifier
- * as an expression.
- * For GROUP BY, it is incorrect to match the grouping item against
- * targetlist entries: according to SQL92, an identifier in GROUP BY
- * is a reference to a column name exposed by FROM, not to a target
- * list column. However, many implementations (including pre-7.0
- * PostgreSQL) accept this anyway. So for GROUP BY, we look first
- * to see if the identifier matches any FROM column name, and only
- * try for a targetlist name if it doesn't. This ensures that we
- * adhere to the spec in the case where the name could be both.
- * DISTINCT ON isn't in the standard, so we can do what we like there;
- * we choose to make it work like ORDER BY, on the rather flimsy
- * grounds that ordinary DISTINCT works on targetlist entries.
- *
- * 2. IntegerConstant
- * This means to use the n'th item in the existing target list.
- * Note that it would make no sense to order/group/distinct by an
- * actual constant, so this does not create a conflict with our
- * extension to order/group by an expression.
- * GROUP BY column-number is not allowed by SQL92, but since
- * the standard has no other behavior defined for this syntax,
- * we may as well accept this common extension.
- *
- * Note that pre-existing resjunk targets must not be used in either case,
- * since the user didn't write them in his SELECT list.
- *
- * If neither special case applies, fall through to treat the item as
- * an expression.
- *----------
- */
- if (IsA(node, ColumnRef) &&
- length(((ColumnRef *) node)->fields) == 1 &&
- ((ColumnRef *) node)->indirection == NIL)
- {
- char *name = strVal(lfirst(((ColumnRef *) node)->fields));
-
- if (clause == GROUP_CLAUSE)
- {
- /*
- * In GROUP BY, we must prefer a match against a FROM-clause
- * column to one against the targetlist. Look to see if there
- * is a matching column. If so, fall through to let
- * transformExpr() do the rest. NOTE: if name could refer
- * ambiguously to more than one column name exposed by FROM,
- * colnameToVar will elog(ERROR). That's just what we want
- * here.
- */
- if (colnameToVar(pstate, name) != NULL)
- name = NULL;
- }
-
- if (name != NULL)
- {
- foreach(tl, tlist)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Resdom *resnode = tle->resdom;
-
- if (!resnode->resjunk &&
- strcmp(resnode->resname, name) == 0)
- {
- if (target_result != NULL)
- {
- if (!equal(target_result->expr, tle->expr))
- elog(ERROR, "%s '%s' is ambiguous",
- clauseText[clause], name);
- }
- else
- target_result = tle;
- /* Stay in loop to check for ambiguity */
- }
- }
- if (target_result != NULL)
- return target_result; /* return the first match */
- }
- }
- if (IsA(node, A_Const))
- {
- Value *val = &((A_Const *) node)->val;
- int targetlist_pos = 0;
- int target_pos;
-
- if (!IsA(val, Integer))
- elog(ERROR, "Non-integer constant in %s", clauseText[clause]);
- target_pos = intVal(val);
- foreach(tl, tlist)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Resdom *resnode = tle->resdom;
-
- if (!resnode->resjunk)
- {
- if (++targetlist_pos == target_pos)
- return tle; /* return the unique match */
- }
- }
- elog(ERROR, "%s position %d is not in target list",
- clauseText[clause], target_pos);
- }
-
- /*
- * Otherwise, we have an expression (this is a Postgres extension not
- * found in SQL92). Convert the untransformed node to a transformed
- * expression, and search for a match in the tlist. NOTE: it doesn't
- * really matter whether there is more than one match. Also, we are
- * willing to match a resjunk target here, though the above cases must
- * ignore resjunk targets.
- */
- expr = transformExpr(pstate, node);
-
- foreach(tl, tlist)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(tl);
-
- if (equal(expr, tle->expr))
- return tle;
- }
-
- /*
- * If no matches, construct a new target entry which is appended to
- * the end of the target list. This target is given resjunk = TRUE so
- * that it will not be projected into the final tuple.
- */
- target_result = transformTargetEntry(pstate, node, expr, NULL, true);
- lappend(tlist, target_result);
-
- return target_result;
-}
-
-
-/*
- * transformGroupClause -
- * transform a Group By clause
- *
- */
-List *
-transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
-{
- List *glist = NIL,
- *gl;
-
- foreach(gl, grouplist)
- {
- TargetEntry *tle;
-
- tle = findTargetlistEntry(pstate, lfirst(gl),
- targetlist, GROUP_CLAUSE);
-
- /* avoid making duplicate grouplist entries */
- if (!exprIsInSortList(tle->expr, glist, targetlist))
- {
- GroupClause *grpcl = makeNode(GroupClause);
-
- grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
-
- grpcl->sortop = any_ordering_op(tle->resdom->restype);
-
- glist = lappend(glist, grpcl);
- }
- }
-
- return glist;
-}
-
-/*
- * transformSortClause -
- * transform an ORDER BY clause
- */
-List *
-transformSortClause(ParseState *pstate,
- List *orderlist,
- List *targetlist)
-{
- List *sortlist = NIL;
- List *olitem;
-
- foreach(olitem, orderlist)
- {
- SortGroupBy *sortby = lfirst(olitem);
- TargetEntry *tle;
-
- tle = findTargetlistEntry(pstate, sortby->node,
- targetlist, ORDER_CLAUSE);
-
- sortlist = addTargetToSortList(tle, sortlist, targetlist,
- sortby->useOp);
- }
-
- return sortlist;
-}
-
-/*
- * transformDistinctClause -
- * transform a DISTINCT or DISTINCT ON clause
- *
- * Since we may need to add items to the query's sortClause list, that list
- * is passed by reference. We might also need to add items to the query's
- * targetlist, but we assume that cannot be empty initially, so we can
- * lappend to it even though the pointer is passed by value.
- */
-List *
-transformDistinctClause(ParseState *pstate, List *distinctlist,
- List *targetlist, List **sortClause)
-{
- List *result = NIL;
- List *slitem;
- List *dlitem;
-
- /* No work if there was no DISTINCT clause */
- if (distinctlist == NIL)
- return NIL;
-
- if (lfirst(distinctlist) == NIL)
- {
- /* We had SELECT DISTINCT */
-
- /*
- * All non-resjunk elements from target list that are not already
- * in the sort list should be added to it. (We don't really care
- * what order the DISTINCT fields are checked in, so we can leave
- * the user's ORDER BY spec alone, and just add additional sort
- * keys to it to ensure that all targetlist items get sorted.)
- */
- *sortClause = addAllTargetsToSortList(*sortClause, targetlist);
-
- /*
- * Now, DISTINCT list consists of all non-resjunk sortlist items.
- * Actually, all the sortlist items had better be non-resjunk!
- * Otherwise, user wrote SELECT DISTINCT with an ORDER BY item
- * that does not appear anywhere in the SELECT targetlist, and we
- * can't implement that with only one sorting pass...
- */
- foreach(slitem, *sortClause)
- {
- SortClause *scl = (SortClause *) lfirst(slitem);
- TargetEntry *tle = get_sortgroupclause_tle(scl, targetlist);
-
- if (tle->resdom->resjunk)
- elog(ERROR, "For SELECT DISTINCT, ORDER BY expressions must appear in target list");
- else
- result = lappend(result, copyObject(scl));
- }
- }
- else
- {
- /* We had SELECT DISTINCT ON (expr, ...) */
-
- /*
- * If the user writes both DISTINCT ON and ORDER BY, then the two
- * expression lists must match (until one or the other runs out).
- * Otherwise the ORDER BY requires a different sort order than the
- * DISTINCT does, and we can't implement that with only one sort
- * pass (and if we do two passes, the results will be rather
- * unpredictable). However, it's OK to have more DISTINCT ON
- * expressions than ORDER BY expressions; we can just add the
- * extra DISTINCT values to the sort list, much as we did above
- * for ordinary DISTINCT fields.
- *
- * Actually, it'd be OK for the common prefixes of the two lists to
- * match in any order, but implementing that check seems like more
- * trouble than it's worth.
- */
- List *nextsortlist = *sortClause;
-
- foreach(dlitem, distinctlist)
- {
- TargetEntry *tle;
-
- tle = findTargetlistEntry(pstate, lfirst(dlitem),
- targetlist, DISTINCT_ON_CLAUSE);
-
- if (nextsortlist != NIL)
- {
- SortClause *scl = (SortClause *) lfirst(nextsortlist);
-
- if (tle->resdom->ressortgroupref != scl->tleSortGroupRef)
- elog(ERROR, "SELECT DISTINCT ON expressions must match initial ORDER BY expressions");
- result = lappend(result, copyObject(scl));
- nextsortlist = lnext(nextsortlist);
- }
- else
- {
- *sortClause = addTargetToSortList(tle, *sortClause,
- targetlist, NIL);
-
- /*
- * Probably, the tle should always have been added at the
- * end of the sort list ... but search to be safe.
- */
- foreach(slitem, *sortClause)
- {
- SortClause *scl = (SortClause *) lfirst(slitem);
-
- if (tle->resdom->ressortgroupref == scl->tleSortGroupRef)
- {
- result = lappend(result, copyObject(scl));
- break;
- }
- }
- if (slitem == NIL)
- elog(ERROR, "transformDistinctClause: failed to add DISTINCT ON clause to target list");
- }
- }
- }
-
- return result;
-}
-
-/*
- * addAllTargetsToSortList
- * Make sure all non-resjunk targets in the targetlist are in the
- * ORDER BY list, adding the not-yet-sorted ones to the end of the list.
- * This is typically used to help implement SELECT DISTINCT.
- *
- * Returns the updated ORDER BY list.
- */
-List *
-addAllTargetsToSortList(List *sortlist, List *targetlist)
-{
- List *i;
-
- foreach(i, targetlist)
- {
- TargetEntry *tle = (TargetEntry *) lfirst(i);
-
- if (!tle->resdom->resjunk)
- sortlist = addTargetToSortList(tle, sortlist, targetlist, NIL);
- }
- return sortlist;
-}
-
-/*
- * addTargetToSortList
- * If the given targetlist entry isn't already in the ORDER BY list,
- * add it to the end of the list, using the sortop with given name
- * or any available sort operator if opname == NIL.
- *
- * Returns the updated ORDER BY list.
- */
-static List *
-addTargetToSortList(TargetEntry *tle, List *sortlist, List *targetlist,
- List *opname)
-{
- /* avoid making duplicate sortlist entries */
- if (!exprIsInSortList(tle->expr, sortlist, targetlist))
- {
- SortClause *sortcl = makeNode(SortClause);
-
- sortcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
-
- if (opname)
- sortcl->sortop = compatible_oper_opid(opname,
- tle->resdom->restype,
- tle->resdom->restype,
- false);
- else
- sortcl->sortop = any_ordering_op(tle->resdom->restype);
-
- sortlist = lappend(sortlist, sortcl);
- }
- return sortlist;
-}
-
-/*
- * assignSortGroupRef
- * Assign the targetentry an unused ressortgroupref, if it doesn't
- * already have one. Return the assigned or pre-existing refnumber.
- *
- * 'tlist' is the targetlist containing (or to contain) the given targetentry.
- */
-Index
-assignSortGroupRef(TargetEntry *tle, List *tlist)
-{
- Index maxRef;
- List *l;
-
- if (tle->resdom->ressortgroupref) /* already has one? */
- return tle->resdom->ressortgroupref;
-
- /* easiest way to pick an unused refnumber: max used + 1 */
- maxRef = 0;
- foreach(l, tlist)
- {
- Index ref = ((TargetEntry *) lfirst(l))->resdom->ressortgroupref;
-
- if (ref > maxRef)
- maxRef = ref;
- }
- tle->resdom->ressortgroupref = maxRef + 1;
- return tle->resdom->ressortgroupref;
-}
-
-/*
- * exprIsInSortList
- * Is the given expression already in the sortlist?
- * Note we will say 'yes' if it is equal() to any sortlist item,
- * even though that might be a different targetlist member.
- *
- * Works for both SortClause and GroupClause lists.
- */
-static bool
-exprIsInSortList(Node *expr, List *sortList, List *targetList)
-{
- List *i;
-
- foreach(i, sortList)
- {
- SortClause *scl = (SortClause *) lfirst(i);
-
- if (equal(expr, get_sortgroupclause_expr(scl, targetList)))
- return true;
- }
- return false;
-}
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
deleted file mode 100644
index 3c441509b1d..00000000000
--- a/src/backend/parser/parse_coerce.c
+++ /dev/null
@@ -1,807 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_coerce.c
- * handle type coercions/conversions for parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.74 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "catalog/pg_proc.h"
-#include "nodes/makefuncs.h"
-#include "optimizer/clauses.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_func.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-
-Oid DemoteType(Oid inType);
-Oid PromoteTypeToNext(Oid inType);
-
-static Oid PreferredType(CATEGORY category, Oid type);
-static Node *build_func_call(Oid funcid, Oid rettype, List *args);
-static Oid find_coercion_function(Oid targetTypeId, Oid inputTypeId,
- Oid secondArgType, bool isExplicit);
-
-
-/* coerce_type()
- * Convert a function argument to a different type.
- */
-Node *
-coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
- Oid targetTypeId, int32 atttypmod, bool isExplicit)
-{
- Node *result;
-
- if (targetTypeId == inputTypeId ||
- targetTypeId == InvalidOid ||
- node == NULL)
- {
- /* no conversion needed */
- result = node;
- }
- else if (inputTypeId == UNKNOWNOID && IsA(node, Const))
- {
- /*
- * Input is a string constant with previously undetermined type.
- * Apply the target type's typinput function to it to produce a
- * constant of the target type.
- *
- * NOTE: this case cannot be folded together with the other
- * constant-input case, since the typinput function does not
- * necessarily behave the same as a type conversion function. For
- * example, int4's typinput function will reject "1.2", whereas
- * float-to-int type conversion will round to integer.
- *
- * XXX if the typinput function is not cachable, we really ought to
- * postpone evaluation of the function call until runtime. But
- * there is no way to represent a typinput function call as an
- * expression tree, because C-string values are not Datums.
- */
- Const *con = (Const *) node;
- Const *newcon = makeNode(Const);
- Type targetType = typeidType(targetTypeId);
-
- newcon->consttype = targetTypeId;
- newcon->constlen = typeLen(targetType);
- newcon->constbyval = typeByVal(targetType);
- newcon->constisnull = con->constisnull;
- newcon->constisset = false;
-
- if (!con->constisnull)
- {
- char *val = DatumGetCString(DirectFunctionCall1(unknownout,
- con->constvalue));
-
- newcon->constvalue = stringTypeDatum(targetType, val, atttypmod);
- pfree(val);
- }
-
- ReleaseSysCache(targetType);
-
- result = (Node *) newcon;
- }
- else if (IsBinaryCompatible(inputTypeId, targetTypeId))
- {
- /*
- * We don't really need to do a conversion, but we do need to
- * attach a RelabelType node so that the expression will be seen
- * to have the intended type when inspected by higher-level code.
- *
- * XXX could we label result with exprTypmod(node) instead of
- * default -1 typmod, to save a possible length-coercion later?
- * Would work if both types have same interpretation of typmod,
- * which is likely but not certain.
- */
- result = (Node *) makeRelabelType(node, targetTypeId, -1);
- }
- else if (typeInheritsFrom(inputTypeId, targetTypeId))
- {
- /*
- * Input class type is a subclass of target, so nothing to do
- * --- except relabel the type. This is binary compatibility
- * for complex types.
- */
- result = (Node *) makeRelabelType(node, targetTypeId, -1);
- }
- else
- {
- /*
- * Otherwise, find the appropriate type conversion function
- * (caller should have determined that there is one), and generate
- * an expression tree representing run-time application of the
- * conversion function.
- *
- * For domains, we use the coercion function for the base type.
- */
- Oid baseTypeId = getBaseType(targetTypeId);
- Oid funcId;
-
- funcId = find_coercion_function(baseTypeId,
- getBaseType(inputTypeId),
- InvalidOid,
- isExplicit);
- if (!OidIsValid(funcId))
- elog(ERROR, "coerce_type: no conversion function from '%s' to '%s'",
- format_type_be(inputTypeId), format_type_be(targetTypeId));
-
- result = build_func_call(funcId, baseTypeId, makeList1(node));
-
- /* if domain, relabel with domain type ID */
- if (targetTypeId != baseTypeId)
- result = (Node *) makeRelabelType(result, targetTypeId, -1);
-
- /*
- * If the input is a constant, apply the type conversion function
- * now instead of delaying to runtime. (We could, of course, just
- * leave this to be done during planning/optimization; but it's a
- * very frequent special case, and we save cycles in the rewriter
- * if we fold the expression now.)
- *
- * Note that no folding will occur if the conversion function is not
- * marked 'iscachable'.
- *
- * HACK: if constant is NULL, don't fold it here. This is needed by
- * make_subplan(), which calls this routine on placeholder Const
- * nodes that mustn't be collapsed. (It'd be a lot cleaner to
- * make a separate node type for that purpose...)
- */
- if (IsA(node, Const) &&
- !((Const *) node)->constisnull)
- result = eval_const_expressions(result);
- }
-
- return result;
-}
-
-
-/* can_coerce_type()
- * Can input_typeids be coerced to func_typeids?
- *
- * There are a few types which are known apriori to be convertible.
- * We will check for those cases first, and then look for possible
- * conversion functions.
- *
- * We must be told whether this is an implicit or explicit coercion
- * (explicit being a CAST construct, explicit function call, etc).
- * We will accept a wider set of coercion cases for an explicit coercion.
- *
- * Notes:
- * This uses the same mechanism as the CAST() SQL construct in gram.y.
- */
-bool
-can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids,
- bool isExplicit)
-{
- int i;
-
- /* run through argument list... */
- for (i = 0; i < nargs; i++)
- {
- Oid inputTypeId = input_typeids[i];
- Oid targetTypeId = func_typeids[i];
- Oid funcId;
-
- /* no problem if same type */
- if (inputTypeId == targetTypeId)
- continue;
-
- /*
- * one of the known-good transparent conversions? then drop
- * through...
- */
- if (IsBinaryCompatible(inputTypeId, targetTypeId))
- continue;
-
- /* don't know what to do for the output type? then quit... */
- if (targetTypeId == InvalidOid)
- return false;
- /* don't know what to do for the input type? then quit... */
- if (inputTypeId == InvalidOid)
- return false;
-
- /*
- * If input is an untyped string constant, assume we can convert
- * it to anything except a class type.
- */
- if (inputTypeId == UNKNOWNOID)
- {
- if (ISCOMPLEX(targetTypeId))
- return false;
- continue;
- }
-
- /*
- * If input is a class type that inherits from target, no problem
- */
- if (typeInheritsFrom(inputTypeId, targetTypeId))
- continue;
-
- /* don't choke on references to no-longer-existing types */
- if (!typeidIsValid(inputTypeId))
- return false;
- if (!typeidIsValid(targetTypeId))
- return false;
-
- /*
- * Else, try for run-time conversion using functions: look for a
- * single-argument function named with the target type name and
- * accepting the source type.
- *
- * If either type is a domain, use its base type instead.
- */
- funcId = find_coercion_function(getBaseType(targetTypeId),
- getBaseType(inputTypeId),
- InvalidOid,
- isExplicit);
- if (!OidIsValid(funcId))
- return false;
- }
-
- return true;
-}
-
-/* coerce_type_typmod()
- * Force a value to a particular typmod, if meaningful and possible.
- *
- * This is applied to values that are going to be stored in a relation
- * (where we have an atttypmod for the column) as well as values being
- * explicitly CASTed (where the typmod comes from the target type spec).
- *
- * The caller must have already ensured that the value is of the correct
- * type, typically by applying coerce_type.
- *
- * If the target column type possesses a function named for the type
- * and having parameter signature (columntype, int4), we assume that
- * the type requires coercion to its own length and that the said
- * function should be invoked to do that.
- *
- * "bpchar" (ie, char(N)) and "numeric" are examples of such types.
- */
-Node *
-coerce_type_typmod(ParseState *pstate, Node *node,
- Oid targetTypeId, int32 atttypmod)
-{
- Oid baseTypeId;
- Oid funcId;
-
- /*
- * A negative typmod is assumed to mean that no coercion is wanted.
- */
- if (atttypmod < 0 || atttypmod == exprTypmod(node))
- return node;
-
- /* If given type is a domain, use base type instead */
- baseTypeId = getBaseType(targetTypeId);
-
- /* Note this is always implicit coercion */
- funcId = find_coercion_function(baseTypeId, baseTypeId, INT4OID, false);
-
- if (OidIsValid(funcId))
- {
- Const *cons;
-
- cons = makeConst(INT4OID,
- sizeof(int32),
- Int32GetDatum(atttypmod),
- false,
- true,
- false,
- false);
-
- node = build_func_call(funcId, baseTypeId, makeList2(node, cons));
-
- /* relabel if it's domain case */
- if (targetTypeId != baseTypeId)
- node = (Node *) makeRelabelType(node, targetTypeId, atttypmod);
- }
-
- return node;
-}
-
-
-/* coerce_to_boolean()
- * Coerce an argument of a construct that requires boolean input
- * (AND, OR, NOT, etc). Also check that input is not a set.
- *
- * Returns the possibly-transformed node tree.
- */
-Node *
-coerce_to_boolean(Node *node, const char *constructName)
-{
- Oid inputTypeId = exprType(node);
- Oid targetTypeId;
-
- if (inputTypeId != BOOLOID)
- {
- targetTypeId = BOOLOID;
- if (!can_coerce_type(1, &inputTypeId, &targetTypeId, false))
- {
- /* translator: first %s is name of a SQL construct, eg WHERE */
- elog(ERROR, "Argument of %s must be type boolean, not type %s",
- constructName, format_type_be(inputTypeId));
- }
- node = coerce_type(NULL, node, inputTypeId, targetTypeId, -1,
- false);
- }
-
- if (expression_returns_set(node))
- {
- /* translator: %s is name of a SQL construct, eg WHERE */
- elog(ERROR, "Argument of %s must not be a set function",
- constructName);
- }
-
- return node;
-}
-
-
-/* select_common_type()
- * Determine the common supertype of a list of input expression types.
- * This is used for determining the output type of CASE and UNION
- * constructs.
- *
- * typeids is a nonempty integer list of type OIDs. Note that earlier items
- * in the list will be preferred if there is doubt.
- * 'context' is a phrase to use in the error message if we fail to select
- * a usable type.
- *
- * XXX this code is WRONG, since (for example) given the input (int4,int8)
- * it will select int4, whereas according to SQL92 clause 9.3 the correct
- * answer is clearly int8. To fix this we need a notion of a promotion
- * hierarchy within type categories --- something more complete than
- * just a single preferred type.
- */
-Oid
-select_common_type(List *typeids, const char *context)
-{
- Oid ptype;
- CATEGORY pcategory;
- List *l;
-
- Assert(typeids != NIL);
- ptype = (Oid) lfirsti(typeids);
- pcategory = TypeCategory(ptype);
- foreach(l, lnext(typeids))
- {
- Oid ntype = (Oid) lfirsti(l);
-
- /* move on to next one if no new information... */
- if ((ntype != InvalidOid) && (ntype != UNKNOWNOID) && (ntype != ptype))
- {
- if ((ptype == InvalidOid) || ptype == UNKNOWNOID)
- {
- /* so far, only nulls so take anything... */
- ptype = ntype;
- pcategory = TypeCategory(ptype);
- }
- else if (TypeCategory(ntype) != pcategory)
- {
- /*
- * both types in different categories? then not much
- * hope...
- */
- elog(ERROR, "%s types '%s' and '%s' not matched",
- context, format_type_be(ptype), format_type_be(ntype));
- }
- else if (IsPreferredType(pcategory, ntype)
- && !IsPreferredType(pcategory, ptype)
- && can_coerce_type(1, &ptype, &ntype, false))
- {
- /*
- * new one is preferred and can convert? then take it...
- */
- ptype = ntype;
- pcategory = TypeCategory(ptype);
- }
- }
- }
-
- /*
- * If all the inputs were UNKNOWN type --- ie, unknown-type literals
- * --- then resolve as type TEXT. This situation comes up with
- * constructs like SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END);
- * SELECT 'foo' UNION SELECT 'bar'; It might seem desirable to leave
- * the construct's output type as UNKNOWN, but that really doesn't
- * work, because we'd probably end up needing a runtime coercion from
- * UNKNOWN to something else, and we usually won't have it. We need
- * to coerce the unknown literals while they are still literals, so a
- * decision has to be made now.
- */
- if (ptype == UNKNOWNOID)
- ptype = TEXTOID;
-
- return ptype;
-}
-
-/* coerce_to_common_type()
- * Coerce an expression to the given type.
- *
- * This is used following select_common_type() to coerce the individual
- * expressions to the desired type. 'context' is a phrase to use in the
- * error message if we fail to coerce.
- *
- * NOTE: pstate may be NULL.
- */
-Node *
-coerce_to_common_type(ParseState *pstate, Node *node,
- Oid targetTypeId,
- const char *context)
-{
- Oid inputTypeId = exprType(node);
-
- if (inputTypeId == targetTypeId)
- return node; /* no work */
- if (can_coerce_type(1, &inputTypeId, &targetTypeId, false))
- node = coerce_type(pstate, node, inputTypeId, targetTypeId, -1,
- false);
- else
- {
- elog(ERROR, "%s unable to convert to type %s",
- context, format_type_be(targetTypeId));
- }
- return node;
-}
-
-
-/* TypeCategory()
- * Assign a category to the specified OID.
- * XXX This should be moved to system catalog lookups
- * to allow for better type extensibility.
- * - thomas 2001-09-30
- */
-CATEGORY
-TypeCategory(Oid inType)
-{
- CATEGORY result;
-
- switch (inType)
- {
- case (BOOLOID):
- result = BOOLEAN_TYPE;
- break;
-
- case (CHAROID):
- case (NAMEOID):
- case (BPCHAROID):
- case (VARCHAROID):
- case (TEXTOID):
- result = STRING_TYPE;
- break;
-
- case (BITOID):
- case (VARBITOID):
- result = BITSTRING_TYPE;
- break;
-
- case (OIDOID):
- case (REGPROCOID):
- case (REGPROCEDUREOID):
- case (REGOPEROID):
- case (REGOPERATOROID):
- case (REGCLASSOID):
- case (REGTYPEOID):
- case (INT2OID):
- case (INT4OID):
- case (INT8OID):
- case (FLOAT4OID):
- case (FLOAT8OID):
- case (NUMERICOID):
- case (CASHOID):
- result = NUMERIC_TYPE;
- break;
-
- case (DATEOID):
- case (TIMEOID):
- case (TIMETZOID):
- case (ABSTIMEOID):
- case (TIMESTAMPOID):
- case (TIMESTAMPTZOID):
- result = DATETIME_TYPE;
- break;
-
- case (RELTIMEOID):
- case (TINTERVALOID):
- case (INTERVALOID):
- result = TIMESPAN_TYPE;
- break;
-
- case (POINTOID):
- case (LSEGOID):
- case (PATHOID):
- case (BOXOID):
- case (POLYGONOID):
- case (LINEOID):
- case (CIRCLEOID):
- result = GEOMETRIC_TYPE;
- break;
-
- case (INETOID):
- case (CIDROID):
- result = NETWORK_TYPE;
- break;
-
- case (UNKNOWNOID):
- case (InvalidOid):
- result = UNKNOWN_TYPE;
- break;
-
- default:
- result = USER_TYPE;
- break;
- }
- return result;
-} /* TypeCategory() */
-
-
-/* IsBinaryCompatible()
- * Check if two types are binary-compatible.
- *
- * This notion allows us to cheat and directly exchange values without
- * going through the trouble of calling a conversion function.
- *
- * XXX This should be moved to system catalog lookups
- * to allow for better type extensibility.
- */
-
-#define TypeIsTextGroup(t) \
- ((t) == TEXTOID || \
- (t) == BPCHAROID || \
- (t) == VARCHAROID)
-
-/* Notice OidGroup is a subset of Int4GroupA */
-#define TypeIsOidGroup(t) \
- ((t) == OIDOID || \
- (t) == REGPROCOID || \
- (t) == REGPROCEDUREOID || \
- (t) == REGOPEROID || \
- (t) == REGOPERATOROID || \
- (t) == REGCLASSOID || \
- (t) == REGTYPEOID)
-
-/*
- * INT4 is binary-compatible with many types, but we don't want to allow
- * implicit coercion directly between, say, OID and AbsTime. So we subdivide
- * the categories.
- */
-#define TypeIsInt4GroupA(t) \
- ((t) == INT4OID || \
- TypeIsOidGroup(t))
-
-#define TypeIsInt4GroupB(t) \
- ((t) == INT4OID || \
- (t) == ABSTIMEOID)
-
-#define TypeIsInt4GroupC(t) \
- ((t) == INT4OID || \
- (t) == RELTIMEOID)
-
-#define TypeIsInetGroup(t) \
- ((t) == INETOID || \
- (t) == CIDROID)
-
-#define TypeIsBitGroup(t) \
- ((t) == BITOID || \
- (t) == VARBITOID)
-
-
-static bool
-DirectlyBinaryCompatible(Oid type1, Oid type2)
-{
- if (type1 == type2)
- return true;
- if (TypeIsTextGroup(type1) && TypeIsTextGroup(type2))
- return true;
- if (TypeIsInt4GroupA(type1) && TypeIsInt4GroupA(type2))
- return true;
- if (TypeIsInt4GroupB(type1) && TypeIsInt4GroupB(type2))
- return true;
- if (TypeIsInt4GroupC(type1) && TypeIsInt4GroupC(type2))
- return true;
- if (TypeIsInetGroup(type1) && TypeIsInetGroup(type2))
- return true;
- if (TypeIsBitGroup(type1) && TypeIsBitGroup(type2))
- return true;
- return false;
-}
-
-
-bool
-IsBinaryCompatible(Oid type1, Oid type2)
-{
- if (DirectlyBinaryCompatible(type1, type2))
- return true;
- /*
- * Perhaps the types are domains; if so, look at their base types
- */
- if (OidIsValid(type1))
- type1 = getBaseType(type1);
- if (OidIsValid(type2))
- type2 = getBaseType(type2);
- if (DirectlyBinaryCompatible(type1, type2))
- return true;
- return false;
-}
-
-
-/* IsPreferredType()
- * Check if this type is a preferred type.
- * XXX This should be moved to system catalog lookups
- * to allow for better type extensibility.
- * - thomas 2001-09-30
- */
-bool
-IsPreferredType(CATEGORY category, Oid type)
-{
- return (type == PreferredType(category, type));
-} /* IsPreferredType() */
-
-
-/* PreferredType()
- * Return the preferred type OID for the specified category.
- * XXX This should be moved to system catalog lookups
- * to allow for better type extensibility.
- * - thomas 2001-09-30
- */
-static Oid
-PreferredType(CATEGORY category, Oid type)
-{
- Oid result;
-
- switch (category)
- {
- case (BOOLEAN_TYPE):
- result = BOOLOID;
- break;
-
- case (STRING_TYPE):
- result = TEXTOID;
- break;
-
- case (BITSTRING_TYPE):
- result = VARBITOID;
- break;
-
- case (NUMERIC_TYPE):
- if (TypeIsOidGroup(type))
- result = OIDOID;
- else if (type == NUMERICOID)
- result = NUMERICOID;
- else
- result = FLOAT8OID;
- break;
-
- case (DATETIME_TYPE):
- if (type == DATEOID)
- result = TIMESTAMPOID;
- else
- result = TIMESTAMPTZOID;
- break;
-
- case (TIMESPAN_TYPE):
- result = INTERVALOID;
- break;
-
- case (NETWORK_TYPE):
- result = INETOID;
- break;
-
- case (GEOMETRIC_TYPE):
- case (USER_TYPE):
- result = type;
- break;
-
- default:
- result = UNKNOWNOID;
- break;
- }
- return result;
-} /* PreferredType() */
-
-/*
- * find_coercion_function
- * Look for a coercion function between two types.
- *
- * A coercion function must be named after (the internal name of) its
- * result type, and must accept exactly the specified input type. We
- * also require it to be defined in the same namespace as its result type.
- * Furthermore, unless we are doing explicit coercion the function must
- * be marked as usable for implicit coercion --- this allows coercion
- * functions to be provided that aren't implicitly invokable.
- *
- * This routine is also used to look for length-coercion functions, which
- * are similar but accept a second argument. secondArgType is the type
- * of the second argument (normally INT4OID), or InvalidOid if we are
- * looking for a regular coercion function.
- *
- * If a function is found, return its pg_proc OID; else return InvalidOid.
- */
-static Oid
-find_coercion_function(Oid targetTypeId, Oid inputTypeId, Oid secondArgType,
- bool isExplicit)
-{
- Oid funcid = InvalidOid;
- Type targetType;
- char *typname;
- Oid typnamespace;
- Oid oid_array[FUNC_MAX_ARGS];
- int nargs;
- HeapTuple ftup;
-
- targetType = typeidType(targetTypeId);
- typname = NameStr(((Form_pg_type) GETSTRUCT(targetType))->typname);
- typnamespace = ((Form_pg_type) GETSTRUCT(targetType))->typnamespace;
-
- MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid));
- oid_array[0] = inputTypeId;
- if (OidIsValid(secondArgType))
- {
- oid_array[1] = secondArgType;
- nargs = 2;
- }
- else
- nargs = 1;
-
- ftup = SearchSysCache(PROCNAMENSP,
- CStringGetDatum(typname),
- Int16GetDatum(nargs),
- PointerGetDatum(oid_array),
- ObjectIdGetDatum(typnamespace));
- if (HeapTupleIsValid(ftup))
- {
- Form_pg_proc pform = (Form_pg_proc) GETSTRUCT(ftup);
-
- /* Make sure the function's result type is as expected */
- if (pform->prorettype == targetTypeId && !pform->proretset &&
- !pform->proisagg)
- {
- /* If needed, make sure it can be invoked implicitly */
- if (isExplicit || pform->proimplicit)
- {
- /* Okay to use it */
- funcid = ftup->t_data->t_oid;
- }
- }
- ReleaseSysCache(ftup);
- }
-
- ReleaseSysCache(targetType);
- return funcid;
-}
-
-/*
- * Build an expression tree representing a function call.
- *
- * The argument expressions must have been transformed already.
- */
-static Node *
-build_func_call(Oid funcid, Oid rettype, List *args)
-{
- Func *funcnode;
- Expr *expr;
-
- funcnode = makeNode(Func);
- funcnode->funcid = funcid;
- funcnode->funcresulttype = rettype;
- funcnode->funcretset = false; /* only possible case here */
- funcnode->func_fcache = NULL;
-
- expr = makeNode(Expr);
- expr->typeOid = rettype;
- expr->opType = FUNC_EXPR;
- expr->oper = (Node *) funcnode;
- expr->args = args;
-
- return (Node *) expr;
-}
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
deleted file mode 100644
index f911238ecce..00000000000
--- a/src/backend/parser/parse_expr.c
+++ /dev/null
@@ -1,1170 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_expr.c
- * handle expressions in parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.119 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "catalog/pg_operator.h"
-#include "catalog/pg_proc.h"
-#include "miscadmin.h"
-#include "nodes/makefuncs.h"
-#include "nodes/params.h"
-#include "parser/analyze.h"
-#include "parser/gramparse.h"
-#include "parser/parse.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_func.h"
-#include "parser/parse_oper.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_target.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-
-int max_expr_depth = DEFAULT_MAX_EXPR_DEPTH;
-static int expr_depth_counter = 0;
-
-bool Transform_null_equals = false;
-
-static Node *parser_typecast_constant(Value *expr, TypeName *typename);
-static Node *parser_typecast_expression(ParseState *pstate,
- Node *expr, TypeName *typename);
-static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
-static Node *transformIndirection(ParseState *pstate, Node *basenode,
- List *indirection);
-
-
-/*
- * Initialize for parsing a new query.
- *
- * We reset the expression depth counter here, in case it was left nonzero
- * due to elog()'ing out of the last parsing operation.
- */
-void
-parse_expr_init(void)
-{
- expr_depth_counter = 0;
-}
-
-
-/*
- * transformExpr -
- * Analyze and transform expressions. Type checking and type casting is
- * done here. The optimizer and the executor cannot handle the original
- * (raw) expressions collected by the parse tree. Hence the transformation
- * here.
- *
- * NOTE: there are various cases in which this routine will get applied to
- * an already-transformed expression. Some examples:
- * 1. At least one construct (BETWEEN/AND) puts the same nodes
- * into two branches of the parse tree; hence, some nodes
- * are transformed twice.
- * 2. Another way it can happen is that coercion of an operator or
- * function argument to the required type (via coerce_type())
- * can apply transformExpr to an already-transformed subexpression.
- * An example here is "SELECT count(*) + 1.0 FROM table".
- * While it might be possible to eliminate these cases, the path of
- * least resistance so far has been to ensure that transformExpr() does
- * no damage if applied to an already-transformed tree. This is pretty
- * easy for cases where the transformation replaces one node type with
- * another, such as A_Const => Const; we just do nothing when handed
- * a Const. More care is needed for node types that are used as both
- * input and output of transformExpr; see SubLink for example.
- */
-Node *
-transformExpr(ParseState *pstate, Node *expr)
-{
- Node *result = NULL;
-
- if (expr == NULL)
- return NULL;
-
- /*
- * Guard against an overly complex expression leading to coredump due
- * to stack overflow here, or in later recursive routines that
- * traverse expression trees. Note that this is very unlikely to
- * happen except with pathological queries; but we don't want someone
- * to be able to crash the backend quite that easily...
- */
- if (++expr_depth_counter > max_expr_depth)
- elog(ERROR, "Expression too complex: nesting depth exceeds max_expr_depth = %d",
- max_expr_depth);
-
- switch (nodeTag(expr))
- {
- case T_ColumnRef:
- {
- result = transformColumnRef(pstate, (ColumnRef *) expr);
- break;
- }
- case T_ParamRef:
- {
- ParamRef *pref = (ParamRef *) expr;
- int paramno = pref->number;
- Oid paramtyp = param_type(paramno);
- Param *param;
- List *fields;
-
- if (!OidIsValid(paramtyp))
- elog(ERROR, "Parameter '$%d' is out of range", paramno);
- param = makeNode(Param);
- param->paramkind = PARAM_NUM;
- param->paramid = (AttrNumber) paramno;
- param->paramname = "<unnamed>";
- param->paramtype = paramtyp;
- result = (Node *) param;
- /* handle qualification, if any */
- foreach(fields, pref->fields)
- {
- result = ParseFuncOrColumn(pstate,
- makeList1(lfirst(fields)),
- makeList1(result),
- false, false, true);
- }
- /* handle subscripts, if any */
- result = transformIndirection(pstate, result,
- pref->indirection);
- break;
- }
- case T_A_Const:
- {
- A_Const *con = (A_Const *) expr;
- Value *val = &con->val;
-
- if (con->typename != NULL)
- result = parser_typecast_constant(val, con->typename);
- else
- result = (Node *) make_const(val);
- break;
- }
- case T_ExprFieldSelect:
- {
- ExprFieldSelect *efs = (ExprFieldSelect *) expr;
- List *fields;
-
- result = transformExpr(pstate, efs->arg);
- /* handle qualification, if any */
- foreach(fields, efs->fields)
- {
- result = ParseFuncOrColumn(pstate,
- makeList1(lfirst(fields)),
- makeList1(result),
- false, false, true);
- }
- /* handle subscripts, if any */
- result = transformIndirection(pstate, result,
- efs->indirection);
- break;
- }
- case T_TypeCast:
- {
- TypeCast *tc = (TypeCast *) expr;
- Node *arg = transformExpr(pstate, tc->arg);
-
- result = parser_typecast_expression(pstate, arg, tc->typename);
- break;
- }
- case T_A_Expr:
- {
- A_Expr *a = (A_Expr *) expr;
-
- switch (a->oper)
- {
- case OP:
- {
- /*
- * Special-case "foo = NULL" and "NULL = foo"
- * for compatibility with standards-broken
- * products (like Microsoft's). Turn these
- * into IS NULL exprs.
- */
- if (Transform_null_equals &&
- length(a->name) == 1 &&
- strcmp(strVal(lfirst(a->name)), "=") == 0 &&
- (exprIsNullConstant(a->lexpr) ||
- exprIsNullConstant(a->rexpr)))
- {
- NullTest *n = makeNode(NullTest);
-
- n->nulltesttype = IS_NULL;
-
- if (exprIsNullConstant(a->lexpr))
- n->arg = a->rexpr;
- else
- n->arg = a->lexpr;
-
- result = transformExpr(pstate,
- (Node *) n);
- }
- else
- {
- Node *lexpr = transformExpr(pstate,
- a->lexpr);
- Node *rexpr = transformExpr(pstate,
- a->rexpr);
-
- result = (Node *) make_op(a->name,
- lexpr,
- rexpr);
- }
- }
- break;
- case AND:
- {
- Node *lexpr = transformExpr(pstate,
- a->lexpr);
- Node *rexpr = transformExpr(pstate,
- a->rexpr);
- Expr *expr = makeNode(Expr);
-
- lexpr = coerce_to_boolean(lexpr, "AND");
- rexpr = coerce_to_boolean(rexpr, "AND");
-
- expr->typeOid = BOOLOID;
- expr->opType = AND_EXPR;
- expr->args = makeList2(lexpr, rexpr);
- result = (Node *) expr;
- }
- break;
- case OR:
- {
- Node *lexpr = transformExpr(pstate,
- a->lexpr);
- Node *rexpr = transformExpr(pstate,
- a->rexpr);
- Expr *expr = makeNode(Expr);
-
- lexpr = coerce_to_boolean(lexpr, "OR");
- rexpr = coerce_to_boolean(rexpr, "OR");
-
- expr->typeOid = BOOLOID;
- expr->opType = OR_EXPR;
- expr->args = makeList2(lexpr, rexpr);
- result = (Node *) expr;
- }
- break;
- case NOT:
- {
- Node *rexpr = transformExpr(pstate,
- a->rexpr);
- Expr *expr = makeNode(Expr);
-
- rexpr = coerce_to_boolean(rexpr, "NOT");
-
- expr->typeOid = BOOLOID;
- expr->opType = NOT_EXPR;
- expr->args = makeList1(rexpr);
- result = (Node *) expr;
- }
- break;
- }
- break;
- }
- case T_FuncCall:
- {
- FuncCall *fn = (FuncCall *) expr;
- List *args;
-
- /* transform the list of arguments */
- foreach(args, fn->args)
- lfirst(args) = transformExpr(pstate,
- (Node *) lfirst(args));
- result = ParseFuncOrColumn(pstate,
- fn->funcname,
- fn->args,
- fn->agg_star,
- fn->agg_distinct,
- false);
- break;
- }
- case T_SubLink:
- {
- SubLink *sublink = (SubLink *) expr;
- List *qtrees;
- Query *qtree;
-
- /* If we already transformed this node, do nothing */
- if (IsA(sublink->subselect, Query))
- {
- result = expr;
- break;
- }
- pstate->p_hasSubLinks = true;
- qtrees = parse_analyze(sublink->subselect, pstate);
- if (length(qtrees) != 1)
- elog(ERROR, "Bad query in subselect");
- qtree = (Query *) lfirst(qtrees);
- if (qtree->commandType != CMD_SELECT ||
- qtree->resultRelation != 0)
- elog(ERROR, "Bad query in subselect");
- sublink->subselect = (Node *) qtree;
-
- if (sublink->subLinkType == EXISTS_SUBLINK)
- {
- /*
- * EXISTS needs no lefthand or combining operator.
- * These fields should be NIL already, but make sure.
- */
- sublink->lefthand = NIL;
- sublink->oper = NIL;
- }
- else if (sublink->subLinkType == EXPR_SUBLINK)
- {
- List *tlist = qtree->targetList;
-
- /*
- * Make sure the subselect delivers a single column
- * (ignoring resjunk targets).
- */
- if (tlist == NIL ||
- ((TargetEntry *) lfirst(tlist))->resdom->resjunk)
- elog(ERROR, "Subselect must have a field");
- while ((tlist = lnext(tlist)) != NIL)
- {
- if (!((TargetEntry *) lfirst(tlist))->resdom->resjunk)
- elog(ERROR, "Subselect must have only one field");
- }
-
- /*
- * EXPR needs no lefthand or combining operator. These
- * fields should be NIL already, but make sure.
- */
- sublink->lefthand = NIL;
- sublink->oper = NIL;
- }
- else
- {
- /* ALL, ANY, or MULTIEXPR: generate operator list */
- List *left_list = sublink->lefthand;
- List *right_list = qtree->targetList;
- List *op;
- char *opname;
- List *elist;
-
- foreach(elist, left_list)
- lfirst(elist) = transformExpr(pstate, lfirst(elist));
-
- Assert(IsA(sublink->oper, A_Expr));
- op = ((A_Expr *) sublink->oper)->name;
- opname = strVal(llast(op));
- sublink->oper = NIL;
-
- /* Combining operators other than =/<> is dubious... */
- if (length(left_list) != 1 &&
- strcmp(opname, "=") != 0 && strcmp(opname, "<>") != 0)
- elog(ERROR, "Row comparison cannot use operator %s",
- opname);
-
- /*
- * Scan subquery's targetlist to find values that will
- * be matched against lefthand values. We need to
- * ignore resjunk targets, so doing the outer
- * iteration over right_list is easier than doing it
- * over left_list.
- */
- while (right_list != NIL)
- {
- TargetEntry *tent = (TargetEntry *) lfirst(right_list);
- Node *lexpr;
- Operator optup;
- Form_pg_operator opform;
- Oper *newop;
-
- right_list = lnext(right_list);
- if (tent->resdom->resjunk)
- continue;
-
- if (left_list == NIL)
- elog(ERROR, "Subselect has too many fields");
- lexpr = lfirst(left_list);
- left_list = lnext(left_list);
-
- /*
- * It's OK to use oper() not compatible_oper()
- * here, because make_subplan() will insert type
- * coercion calls if needed.
- */
- optup = oper(op,
- exprType(lexpr),
- exprType(tent->expr),
- false);
- opform = (Form_pg_operator) GETSTRUCT(optup);
-
- if (opform->oprresult != BOOLOID)
- elog(ERROR, "%s has result type of %s, but must return %s"
- " to be used with quantified predicate subquery",
- opname, format_type_be(opform->oprresult),
- format_type_be(BOOLOID));
-
- if (get_func_retset(opform->oprcode))
- elog(ERROR, "%s must not return a set"
- " to be used with quantified predicate subquery",
- opname);
-
- newop = makeOper(oprid(optup), /* opno */
- InvalidOid, /* opid */
- opform->oprresult,
- false);
- sublink->oper = lappend(sublink->oper, newop);
- ReleaseSysCache(optup);
- }
- if (left_list != NIL)
- elog(ERROR, "Subselect has too few fields");
- }
- result = (Node *) expr;
- break;
- }
-
- case T_CaseExpr:
- {
- CaseExpr *c = (CaseExpr *) expr;
- CaseExpr *newc = makeNode(CaseExpr);
- List *newargs = NIL;
- List *typeids = NIL;
- List *args;
- Node *defresult;
- Oid ptype;
-
- /* transform the list of arguments */
- foreach(args, c->args)
- {
- CaseWhen *w = (CaseWhen *) lfirst(args);
- CaseWhen *neww = makeNode(CaseWhen);
- Node *warg;
-
- Assert(IsA(w, CaseWhen));
-
- warg = w->expr;
- if (c->arg != NULL)
- {
- /* shorthand form was specified, so expand... */
- warg = (Node *) makeSimpleA_Expr(OP, "=",
- c->arg, warg);
- }
- neww->expr = transformExpr(pstate, warg);
-
- neww->expr = coerce_to_boolean(neww->expr, "CASE/WHEN");
-
- /*
- * result is NULL for NULLIF() construct - thomas
- * 1998-11-11
- */
- warg = w->result;
- if (warg == NULL)
- {
- A_Const *n = makeNode(A_Const);
-
- n->val.type = T_Null;
- warg = (Node *) n;
- }
- neww->result = transformExpr(pstate, warg);
-
- newargs = lappend(newargs, neww);
- typeids = lappendi(typeids, exprType(neww->result));
- }
-
- newc->args = newargs;
-
- /*
- * It's not shorthand anymore, so drop the implicit
- * argument. This is necessary to keep any re-application
- * of transformExpr from doing the wrong thing.
- */
- newc->arg = NULL;
-
- /* transform the default clause */
- defresult = c->defresult;
- if (defresult == NULL)
- {
- A_Const *n = makeNode(A_Const);
-
- n->val.type = T_Null;
- defresult = (Node *) n;
- }
- newc->defresult = transformExpr(pstate, defresult);
-
- /*
- * Note: default result is considered the most significant
- * type in determining preferred type. This is how the
- * code worked before, but it seems a little bogus to me
- * --- tgl
- */
- typeids = lconsi(exprType(newc->defresult), typeids);
-
- ptype = select_common_type(typeids, "CASE");
- newc->casetype = ptype;
-
- /* Convert default result clause, if necessary */
- newc->defresult = coerce_to_common_type(pstate,
- newc->defresult,
- ptype,
- "CASE/ELSE");
-
- /* Convert when-clause results, if necessary */
- foreach(args, newc->args)
- {
- CaseWhen *w = (CaseWhen *) lfirst(args);
-
- w->result = coerce_to_common_type(pstate,
- w->result,
- ptype,
- "CASE/WHEN");
- }
-
- result = (Node *) newc;
- break;
- }
-
- case T_NullTest:
- {
- NullTest *n = (NullTest *) expr;
-
- n->arg = transformExpr(pstate, n->arg);
- /* the argument can be any type, so don't coerce it */
- result = expr;
- break;
- }
-
- case T_BooleanTest:
- {
- BooleanTest *b = (BooleanTest *) expr;
- const char *clausename;
-
- switch (b->booltesttype)
- {
- case IS_TRUE:
- clausename = "IS TRUE";
- break;
- case IS_NOT_TRUE:
- clausename = "IS NOT TRUE";
- break;
- case IS_FALSE:
- clausename = "IS FALSE";
- break;
- case IS_NOT_FALSE:
- clausename = "IS NOT FALSE";
- break;
- case IS_UNKNOWN:
- clausename = "IS UNKNOWN";
- break;
- case IS_NOT_UNKNOWN:
- clausename = "IS NOT UNKNOWN";
- break;
- default:
- elog(ERROR, "transformExpr: unexpected booltesttype %d",
- (int) b->booltesttype);
- clausename = NULL; /* keep compiler quiet */
- }
-
- b->arg = transformExpr(pstate, b->arg);
-
- b->arg = coerce_to_boolean(b->arg, clausename);
-
- result = expr;
- break;
- }
-
- /*
- * Quietly accept node types that may be presented when we are
- * called on an already-transformed tree.
- *
- * Do any other node types need to be accepted? For now we are
- * taking a conservative approach, and only accepting node
- * types that are demonstrably necessary to accept.
- */
- case T_Expr:
- case T_Var:
- case T_Const:
- case T_Param:
- case T_Aggref:
- case T_ArrayRef:
- case T_FieldSelect:
- case T_RelabelType:
- {
- result = (Node *) expr;
- break;
- }
-
- default:
- /* should not reach here */
- elog(ERROR, "transformExpr: does not know how to transform node %d"
- " (internal error)", nodeTag(expr));
- break;
- }
-
- expr_depth_counter--;
-
- return result;
-}
-
-static Node *
-transformIndirection(ParseState *pstate, Node *basenode, List *indirection)
-{
- if (indirection == NIL)
- return basenode;
- return (Node *) transformArraySubscripts(pstate,
- basenode, exprType(basenode),
- indirection, false, NULL);
-}
-
-static Node *
-transformColumnRef(ParseState *pstate, ColumnRef *cref)
-{
- int numnames = length(cref->fields);
- Node *node;
- RangeVar *rv;
-
- /*----------
- * The allowed syntaxes are:
- *
- * A First try to resolve as unqualified column name;
- * if no luck, try to resolve as unqual. table name (A.*).
- * A.B A is an unqual. table name; B is either a
- * column or function name (trying column name first).
- * A.B.C schema A, table B, col or func name C.
- * A.B.C.D catalog A, schema B, table C, col or func D.
- * A.* A is an unqual. table name; means whole-row value.
- * A.B.* whole-row value of table B in schema A.
- * A.B.C.* whole-row value of table C in schema B in catalog A.
- *
- * We do not need to cope with bare "*"; that will only be accepted by
- * the grammar at the top level of a SELECT list, and transformTargetList
- * will take care of it before it ever gets here.
- *
- * Currently, if a catalog name is given then it must equal the current
- * database name; we check it here and then discard it.
- *
- * For whole-row references, the result is an untransformed RangeVar,
- * which will work as the argument to a function call, but not in any
- * other context at present. (We could instead coerce to a whole-row Var,
- * but that will fail for subselect and join RTEs, because there is no
- * pg_type entry for their rowtypes.)
- *----------
- */
- switch (numnames)
- {
- case 1:
- {
- char *name = strVal(lfirst(cref->fields));
-
- /* Try to identify as an unqualified column */
- node = colnameToVar(pstate, name);
- if (node == NULL)
- {
- /*
- * Not known as a column of any range-table entry, so
- * try to find the name as a relation ... but not if
- * subscripts appear. Note also that only relations
- * already entered into the rangetable will be recognized.
- */
- int levels_up;
-
- if (cref->indirection == NIL &&
- refnameRangeTblEntry(pstate, name, &levels_up) != NULL)
- {
- rv = makeNode(RangeVar);
- rv->relname = name;
- rv->inhOpt = INH_DEFAULT;
- node = (Node *) rv;
- }
- else
- elog(ERROR, "Attribute \"%s\" not found", name);
- }
- break;
- }
- case 2:
- {
- char *name1 = strVal(lfirst(cref->fields));
- char *name2 = strVal(lsecond(cref->fields));
-
- /* Whole-row reference? */
- if (strcmp(name2, "*") == 0)
- {
- rv = makeNode(RangeVar);
- rv->relname = name1;
- rv->inhOpt = INH_DEFAULT;
- node = (Node *) rv;
- break;
- }
-
- /* Try to identify as a once-qualified column */
- node = qualifiedNameToVar(pstate, name1, name2, true);
- if (node == NULL)
- {
- /*
- * Not known as a column of any range-table entry, so
- * try it as a function call. Here, we will create an
- * implicit RTE for tables not already entered.
- */
- rv = makeNode(RangeVar);
- rv->relname = name1;
- rv->inhOpt = INH_DEFAULT;
- node = ParseFuncOrColumn(pstate,
- makeList1(makeString(name2)),
- makeList1(rv),
- false, false, true);
- }
- break;
- }
- case 3:
- {
- char *name1 = strVal(lfirst(cref->fields));
- char *name2 = strVal(lsecond(cref->fields));
- char *name3 = strVal(lfirst(lnext(lnext(cref->fields))));
-
- /* Whole-row reference? */
- if (strcmp(name3, "*") == 0)
- {
- rv = makeNode(RangeVar);
- rv->schemaname = name1;
- rv->relname = name2;
- rv->inhOpt = INH_DEFAULT;
- node = (Node *) rv;
- break;
- }
-
- /* Try to identify as a twice-qualified column */
- /* XXX do something with schema name here */
- node = qualifiedNameToVar(pstate, name2, name3, true);
- if (node == NULL)
- {
- /* Try it as a function call */
- rv = makeNode(RangeVar);
- rv->schemaname = name1;
- rv->relname = name2;
- rv->inhOpt = INH_DEFAULT;
- node = ParseFuncOrColumn(pstate,
- makeList1(makeString(name3)),
- makeList1(rv),
- false, false, true);
- }
- break;
- }
- case 4:
- {
- char *name1 = strVal(lfirst(cref->fields));
- char *name2 = strVal(lsecond(cref->fields));
- char *name3 = strVal(lfirst(lnext(lnext(cref->fields))));
- char *name4 = strVal(lfirst(lnext(lnext(lnext(cref->fields)))));
-
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(name1, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
-
- /* Whole-row reference? */
- if (strcmp(name4, "*") == 0)
- {
- rv = makeNode(RangeVar);
- rv->schemaname = name2;
- rv->relname = name3;
- rv->inhOpt = INH_DEFAULT;
- node = (Node *) rv;
- break;
- }
-
- /* Try to identify as a twice-qualified column */
- /* XXX do something with schema name here */
- node = qualifiedNameToVar(pstate, name3, name4, true);
- if (node == NULL)
- {
- /* Try it as a function call */
- rv = makeNode(RangeVar);
- rv->schemaname = name2;
- rv->relname = name3;
- rv->inhOpt = INH_DEFAULT;
- node = ParseFuncOrColumn(pstate,
- makeList1(makeString(name4)),
- makeList1(rv),
- false, false, true);
- }
- break;
- }
- default:
- elog(ERROR, "Invalid qualified name syntax (too many names)");
- node = NULL; /* keep compiler quiet */
- break;
- }
-
- return transformIndirection(pstate, node, cref->indirection);
-}
-
-/*
- * exprType -
- * returns the Oid of the type of the expression. (Used for typechecking.)
- */
-Oid
-exprType(Node *expr)
-{
- Oid type = (Oid) InvalidOid;
-
- if (!expr)
- return type;
-
- switch (nodeTag(expr))
- {
- case T_Var:
- type = ((Var *) expr)->vartype;
- break;
- case T_Expr:
- type = ((Expr *) expr)->typeOid;
- break;
- case T_Const:
- type = ((Const *) expr)->consttype;
- break;
- case T_ArrayRef:
- type = ((ArrayRef *) expr)->refelemtype;
- break;
- case T_Aggref:
- type = ((Aggref *) expr)->aggtype;
- break;
- case T_Param:
- type = ((Param *) expr)->paramtype;
- break;
- case T_FieldSelect:
- type = ((FieldSelect *) expr)->resulttype;
- break;
- case T_RelabelType:
- type = ((RelabelType *) expr)->resulttype;
- break;
- case T_SubLink:
- {
- SubLink *sublink = (SubLink *) expr;
-
- if (sublink->subLinkType == EXPR_SUBLINK)
- {
- /* get the type of the subselect's first target column */
- Query *qtree = (Query *) sublink->subselect;
- TargetEntry *tent;
-
- if (!qtree || !IsA(qtree, Query))
- elog(ERROR, "Cannot get type for untransformed sublink");
- tent = (TargetEntry *) lfirst(qtree->targetList);
- type = tent->resdom->restype;
- }
- else
- {
- /* for all other sublink types, result is boolean */
- type = BOOLOID;
- }
- }
- break;
- case T_CaseExpr:
- type = ((CaseExpr *) expr)->casetype;
- break;
- case T_CaseWhen:
- type = exprType(((CaseWhen *) expr)->result);
- break;
- case T_NullTest:
- type = BOOLOID;
- break;
- case T_BooleanTest:
- type = BOOLOID;
- break;
- default:
- elog(ERROR, "Do not know how to get type for %d node",
- nodeTag(expr));
- break;
- }
- return type;
-}
-
-/*
- * exprTypmod -
- * returns the type-specific attrmod of the expression, if it can be
- * determined. In most cases, it can't and we return -1.
- */
-int32
-exprTypmod(Node *expr)
-{
- if (!expr)
- return -1;
-
- switch (nodeTag(expr))
- {
- case T_Var:
- return ((Var *) expr)->vartypmod;
- case T_Const:
- {
- /* Be smart about string constants... */
- Const *con = (Const *) expr;
-
- switch (con->consttype)
- {
- case BPCHAROID:
- if (!con->constisnull)
- return VARSIZE(DatumGetPointer(con->constvalue));
- break;
- default:
- break;
- }
- }
- break;
- case T_Expr:
- {
- int32 coercedTypmod;
-
- /* Be smart about length-coercion functions... */
- if (exprIsLengthCoercion(expr, &coercedTypmod))
- return coercedTypmod;
- }
- break;
- case T_FieldSelect:
- return ((FieldSelect *) expr)->resulttypmod;
- break;
- case T_RelabelType:
- return ((RelabelType *) expr)->resulttypmod;
- break;
- case T_CaseExpr:
- {
- /*
- * If all the alternatives agree on type/typmod, return
- * that typmod, else use -1
- */
- CaseExpr *cexpr = (CaseExpr *) expr;
- Oid casetype = cexpr->casetype;
- int32 typmod;
- List *arg;
-
- if (!cexpr->defresult)
- return -1;
- if (exprType(cexpr->defresult) != casetype)
- return -1;
- typmod = exprTypmod(cexpr->defresult);
- if (typmod < 0)
- return -1; /* no point in trying harder */
- foreach(arg, cexpr->args)
- {
- CaseWhen *w = (CaseWhen *) lfirst(arg);
-
- Assert(IsA(w, CaseWhen));
- if (exprType(w->result) != casetype)
- return -1;
- if (exprTypmod(w->result) != typmod)
- return -1;
- }
- return typmod;
- }
- break;
- default:
- break;
- }
- return -1;
-}
-
-/*
- * exprIsLengthCoercion
- * Detect whether an expression tree is an application of a datatype's
- * typmod-coercion function. Optionally extract the result's typmod.
- *
- * If coercedTypmod is not NULL, the typmod is stored there if the expression
- * is a length-coercion function, else -1 is stored there.
- *
- * We assume that a two-argument function named for a datatype, whose
- * output and first argument types are that datatype, and whose second
- * input is an int32 constant, represents a forced length coercion.
- *
- * XXX It'd be better if the parsetree retained some explicit indication
- * of the coercion, so we didn't need these heuristics.
- */
-bool
-exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
-{
- Func *func;
- Const *second_arg;
- HeapTuple procTuple;
- HeapTuple typeTuple;
- Form_pg_proc procStruct;
- Form_pg_type typeStruct;
-
- if (coercedTypmod != NULL)
- *coercedTypmod = -1; /* default result on failure */
-
- /* Is it a function-call at all? */
- if (expr == NULL ||
- !IsA(expr, Expr) ||
- ((Expr *) expr)->opType != FUNC_EXPR)
- return false;
- func = (Func *) (((Expr *) expr)->oper);
- Assert(IsA(func, Func));
-
- /*
- * If it's not a two-argument function with the second argument being
- * an int4 constant, it can't have been created from a length
- * coercion.
- */
- if (length(((Expr *) expr)->args) != 2)
- return false;
- second_arg = (Const *) lsecond(((Expr *) expr)->args);
- if (!IsA(second_arg, Const) ||
- second_arg->consttype != INT4OID ||
- second_arg->constisnull)
- return false;
-
- /*
- * Lookup the function in pg_proc
- */
- procTuple = SearchSysCache(PROCOID,
- ObjectIdGetDatum(func->funcid),
- 0, 0, 0);
- if (!HeapTupleIsValid(procTuple))
- elog(ERROR, "cache lookup for proc %u failed", func->funcid);
- procStruct = (Form_pg_proc) GETSTRUCT(procTuple);
-
- /*
- * It must be a function with two arguments where the first is of the
- * same type as the return value and the second is an int4. Also, just
- * to be sure, check return type agrees with expr node.
- */
- if (procStruct->pronargs != 2 ||
- procStruct->prorettype != procStruct->proargtypes[0] ||
- procStruct->proargtypes[1] != INT4OID ||
- procStruct->prorettype != ((Expr *) expr)->typeOid)
- {
- ReleaseSysCache(procTuple);
- return false;
- }
-
- /*
- * Furthermore, the name and namespace of the function must be the same
- * as its result type's name/namespace (cf. find_coercion_function).
- */
- typeTuple = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(procStruct->prorettype),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTuple))
- elog(ERROR, "cache lookup for type %u failed",
- procStruct->prorettype);
- typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
- if (strcmp(NameStr(procStruct->proname),
- NameStr(typeStruct->typname)) != 0 ||
- procStruct->pronamespace != typeStruct->typnamespace)
- {
- ReleaseSysCache(procTuple);
- ReleaseSysCache(typeTuple);
- return false;
- }
-
- /*
- * OK, it is indeed a length-coercion function.
- */
- if (coercedTypmod != NULL)
- *coercedTypmod = DatumGetInt32(second_arg->constvalue);
-
- ReleaseSysCache(procTuple);
- ReleaseSysCache(typeTuple);
- return true;
-}
-
-/*
- * Produce an appropriate Const node from a constant value produced
- * by the parser and an explicit type name to cast to.
- */
-static Node *
-parser_typecast_constant(Value *expr, TypeName *typename)
-{
- Type tp;
- Datum datum;
- Const *con;
- char *const_string = NULL;
- bool string_palloced = false;
- bool isNull = false;
-
- tp = typenameType(typename);
-
- switch (nodeTag(expr))
- {
- case T_Integer:
- const_string = DatumGetCString(DirectFunctionCall1(int4out,
- Int32GetDatum(expr->val.ival)));
- string_palloced = true;
- break;
- case T_Float:
- case T_String:
- case T_BitString:
- const_string = expr->val.str;
- break;
- case T_Null:
- isNull = true;
- break;
- default:
- elog(ERROR, "Cannot cast this expression to type '%s'",
- typeTypeName(tp));
- }
-
- if (isNull)
- datum = (Datum) NULL;
- else
- datum = stringTypeDatum(tp, const_string, typename->typmod);
-
- con = makeConst(typeTypeId(tp),
- typeLen(tp),
- datum,
- isNull,
- typeByVal(tp),
- false, /* not a set */
- true /* is cast */ );
-
- if (string_palloced)
- pfree(const_string);
-
- ReleaseSysCache(tp);
-
- return (Node *) con;
-}
-
-/*
- * Handle an explicit CAST applied to a non-constant expression.
- * (Actually, this works for constants too, but gram.y won't generate
- * a TypeCast node if the argument is just a constant.)
- *
- * The given expr has already been transformed, but we need to lookup
- * the type name and then apply any necessary coercion function(s).
- */
-static Node *
-parser_typecast_expression(ParseState *pstate,
- Node *expr, TypeName *typename)
-{
- Oid inputType = exprType(expr);
- Oid targetType;
-
- targetType = typenameTypeId(typename);
-
- if (inputType == InvalidOid)
- return expr; /* do nothing if NULL input */
-
- if (inputType != targetType)
- {
- expr = CoerceTargetExpr(pstate, expr, inputType,
- targetType, typename->typmod,
- true); /* explicit coercion */
- if (expr == NULL)
- elog(ERROR, "Cannot cast type '%s' to '%s'",
- format_type_be(inputType),
- format_type_be(targetType));
- }
-
- /*
- * If the target is a fixed-length type, it may need a length coercion
- * as well as a type coercion.
- */
- expr = coerce_type_typmod(pstate, expr,
- targetType, typename->typmod);
-
- return expr;
-}
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
deleted file mode 100644
index f92bbe8ac5c..00000000000
--- a/src/backend/parser/parse_func.c
+++ /dev/null
@@ -1,1387 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_func.c
- * handle function calls in parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.132 2002/06/20 20:29:32 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "access/heapam.h"
-#include "catalog/catname.h"
-#include "catalog/namespace.h"
-#include "catalog/pg_inherits.h"
-#include "catalog/pg_proc.h"
-#include "lib/stringinfo.h"
-#include "nodes/makefuncs.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_func.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/fmgroids.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-
-static Node *ParseComplexProjection(ParseState *pstate,
- char *funcname,
- Node *first_arg);
-static Oid **argtype_inherit(int nargs, Oid *argtypes);
-
-static int find_inheritors(Oid relid, Oid **supervec);
-static Oid **gen_cross_product(InhPaths *arginh, int nargs);
-static void make_arguments(ParseState *pstate,
- int nargs,
- List *fargs,
- Oid *input_typeids,
- Oid *function_typeids);
-static int match_argtypes(int nargs,
- Oid *input_typeids,
- FuncCandidateList function_typeids,
- FuncCandidateList *candidates);
-static FieldSelect *setup_field_select(Node *input, char *attname, Oid relid);
-static FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids,
- FuncCandidateList candidates);
-
-
-/*
- * Parse a function call
- *
- * For historical reasons, Postgres tries to treat the notations tab.col
- * and col(tab) as equivalent: if a single-argument function call has an
- * argument of complex type and the (unqualified) function name matches
- * any attribute of the type, we take it as a column projection.
- *
- * Hence, both cases come through here. The is_column parameter tells us
- * which syntactic construct is actually being dealt with, but this is
- * intended to be used only to deliver an appropriate error message,
- * not to affect the semantics. When is_column is true, we should have
- * a single argument (the putative table), unqualified function name
- * equal to the column name, and no aggregate decoration.
- *
- * In the function-call case, the argument expressions have been transformed
- * already. In the column case, we may get either a transformed expression
- * or a RangeVar node as argument.
- */
-Node *
-ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
- bool agg_star, bool agg_distinct, bool is_column)
-{
- Oid rettype;
- Oid funcid;
- List *i;
- Node *first_arg = NULL;
- char *refname;
- int nargs = length(fargs);
- int argn;
- Oid oid_array[FUNC_MAX_ARGS];
- Oid *true_oid_array;
- Node *retval;
- bool retset;
- FuncDetailCode fdresult;
-
- /*
- * Most of the rest of the parser just assumes that functions do not
- * have more than FUNC_MAX_ARGS parameters. We have to test here to
- * protect against array overruns, etc. Of course, this may not be a
- * function, but the test doesn't hurt.
- */
- if (nargs > FUNC_MAX_ARGS)
- elog(ERROR, "Cannot pass more than %d arguments to a function",
- FUNC_MAX_ARGS);
-
- if (fargs)
- {
- first_arg = lfirst(fargs);
- if (first_arg == NULL) /* should not happen */
- elog(ERROR, "Function '%s' does not allow NULL input",
- NameListToString(funcname));
- }
-
- /*
- * check for column projection: if function has one argument, and that
- * argument is of complex type, and function name is not qualified,
- * then the "function call" could be a projection. We also check
- * that there wasn't any aggregate decoration.
- */
- if (nargs == 1 && !agg_star && !agg_distinct && length(funcname) == 1)
- {
- char *cname = strVal(lfirst(funcname));
-
- /* Is it a not-yet-transformed RangeVar node? */
- if (IsA(first_arg, RangeVar))
- {
- /* First arg is a relation. This could be a projection. */
- refname = ((RangeVar *) first_arg)->relname;
-
- /* XXX WRONG: ignores possible qualification of argument */
- retval = qualifiedNameToVar(pstate, refname, cname, true);
- if (retval)
- return retval;
- }
- else if (ISCOMPLEX(exprType(first_arg)))
- {
- /*
- * Attempt to handle projection of a complex argument. If
- * ParseComplexProjection can't handle the projection, we have
- * to keep going.
- */
- retval = ParseComplexProjection(pstate, cname, first_arg);
- if (retval)
- return retval;
- }
- }
-
- /*
- * Okay, it's not a column projection, so it must really be a function.
- * Extract arg type info and transform RangeVar arguments into varnodes
- * of the appropriate form.
- */
- MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid));
-
- argn = 0;
- foreach(i, fargs)
- {
- Node *arg = lfirst(i);
- Oid toid;
-
- if (IsA(arg, RangeVar))
- {
- RangeTblEntry *rte;
- int vnum;
- int sublevels_up;
-
- /*
- * a relation
- */
- refname = ((RangeVar *) arg)->relname;
-
- rte = refnameRangeTblEntry(pstate, refname,
- &sublevels_up);
-
- if (rte == NULL)
- rte = addImplicitRTE(pstate, (RangeVar *) arg);
-
- vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
-
- /*
- * The parameter to be passed to the function is the whole
- * tuple from the relation. We build a special VarNode to
- * reflect this -- it has varno set to the correct range table
- * entry, but has varattno == 0 to signal that the whole tuple
- * is the argument. Also, it has typmod set to
- * sizeof(Pointer) to signal that the runtime representation
- * will be a pointer not an Oid.
- */
- switch (rte->rtekind)
- {
- case RTE_RELATION:
- toid = get_rel_type_id(rte->relid);
- if (!OidIsValid(toid))
- elog(ERROR, "Cannot find type OID for relation %u",
- rte->relid);
- break;
- case RTE_FUNCTION:
- toid = exprType(rte->funcexpr);
- break;
- default:
- /*
- * RTE is a join or subselect; must fail for lack of a
- * named tuple type
- */
- if (is_column)
- elog(ERROR, "No such attribute %s.%s",
- refname, strVal(lfirst(funcname)));
- else
- elog(ERROR, "Cannot pass result of sub-select or join %s to a function",
- refname);
- toid = InvalidOid; /* keep compiler quiet */
- break;
- }
-
- /* replace RangeVar in the arg list */
- lfirst(i) = makeVar(vnum,
- InvalidAttrNumber,
- toid,
- sizeof(Pointer),
- sublevels_up);
- }
- else
- toid = exprType(arg);
-
- oid_array[argn++] = toid;
- }
-
- /*
- * func_get_detail looks up the function in the catalogs, does
- * disambiguation for polymorphic functions, handles inheritance,
- * and returns the funcid and type and set or singleton status of
- * the function's return value. it also returns the true argument
- * types to the function.
- */
- fdresult = func_get_detail(funcname, fargs, nargs, oid_array,
- &funcid, &rettype, &retset,
- &true_oid_array);
- if (fdresult == FUNCDETAIL_COERCION)
- {
- /*
- * We can do it as a trivial coercion. coerce_type can handle
- * these cases, so why duplicate code...
- */
- return coerce_type(pstate, lfirst(fargs),
- oid_array[0], rettype, -1, true);
- }
- else if (fdresult == FUNCDETAIL_NORMAL)
- {
- /*
- * Normal function found; was there anything indicating it must be
- * an aggregate?
- */
- if (agg_star)
- elog(ERROR, "%s(*) specified, but %s is not an aggregate function",
- NameListToString(funcname), NameListToString(funcname));
- if (agg_distinct)
- elog(ERROR, "DISTINCT specified, but %s is not an aggregate function",
- NameListToString(funcname));
- }
- else if (fdresult != FUNCDETAIL_AGGREGATE)
- {
- /*
- * Oops. Time to die.
- *
- * If we are dealing with the attribute notation rel.function,
- * give an error message that is appropriate for that case.
- */
- if (is_column)
- {
- char *colname = strVal(lfirst(funcname));
- Oid relTypeId;
-
- Assert(nargs == 1);
- if (IsA(first_arg, RangeVar))
- elog(ERROR, "No such attribute %s.%s",
- ((RangeVar *) first_arg)->relname, colname);
- relTypeId = exprType(first_arg);
- if (!ISCOMPLEX(relTypeId))
- elog(ERROR, "Attribute notation .%s applied to type %s, which is not a complex type",
- colname, format_type_be(relTypeId));
- else
- elog(ERROR, "Attribute \"%s\" not found in datatype %s",
- colname, format_type_be(relTypeId));
- }
- /*
- * Else generate a detailed complaint for a function
- */
- func_error(NULL, funcname, nargs, oid_array,
- "Unable to identify a function that satisfies the "
- "given argument types"
- "\n\tYou may need to add explicit typecasts");
- }
-
- /* perform the necessary typecasting of arguments */
- make_arguments(pstate, nargs, fargs, oid_array, true_oid_array);
-
- /* build the appropriate output structure */
- if (fdresult == FUNCDETAIL_NORMAL)
- {
- Expr *expr = makeNode(Expr);
- Func *funcnode = makeNode(Func);
-
- funcnode->funcid = funcid;
- funcnode->funcresulttype = rettype;
- funcnode->funcretset = retset;
- funcnode->func_fcache = NULL;
-
- expr->typeOid = rettype;
- expr->opType = FUNC_EXPR;
- expr->oper = (Node *) funcnode;
- expr->args = fargs;
-
- retval = (Node *) expr;
- }
- else
- {
- /* aggregate function */
- Aggref *aggref = makeNode(Aggref);
-
- aggref->aggfnoid = funcid;
- aggref->aggtype = rettype;
- aggref->target = lfirst(fargs);
- aggref->aggstar = agg_star;
- aggref->aggdistinct = agg_distinct;
-
- retval = (Node *) aggref;
-
- if (retset)
- elog(ERROR, "Aggregates may not return sets");
-
- pstate->p_hasAggs = true;
- }
-
- return retval;
-}
-
-
-/* match_argtypes()
- *
- * Given a list of possible typeid arrays to a function and an array of
- * input typeids, produce a shortlist of those function typeid arrays
- * that match the input typeids (either exactly or by coercion), and
- * return the number of such arrays.
- *
- * NB: okay to modify input list structure, as long as we find at least
- * one match.
- */
-static int
-match_argtypes(int nargs,
- Oid *input_typeids,
- FuncCandidateList function_typeids,
- FuncCandidateList *candidates) /* return value */
-{
- FuncCandidateList current_candidate;
- FuncCandidateList next_candidate;
- int ncandidates = 0;
-
- *candidates = NULL;
-
- for (current_candidate = function_typeids;
- current_candidate != NULL;
- current_candidate = next_candidate)
- {
- next_candidate = current_candidate->next;
- if (can_coerce_type(nargs, input_typeids, current_candidate->args,
- false))
- {
- current_candidate->next = *candidates;
- *candidates = current_candidate;
- ncandidates++;
- }
- }
-
- return ncandidates;
-} /* match_argtypes() */
-
-
-/* func_select_candidate()
- * Given the input argtype array and more than one candidate
- * for the function, attempt to resolve the conflict.
- * Returns the selected candidate if the conflict can be resolved,
- * otherwise returns NULL.
- *
- * By design, this is pretty similar to oper_select_candidate in parse_oper.c.
- * However, the calling convention is a little different: we assume the caller
- * already pruned away "candidates" that aren't actually coercion-compatible
- * with the input types, whereas oper_select_candidate must do that itself.
- */
-static FuncCandidateList
-func_select_candidate(int nargs,
- Oid *input_typeids,
- FuncCandidateList candidates)
-{
- FuncCandidateList current_candidate;
- FuncCandidateList last_candidate;
- Oid *current_typeids;
- Oid current_type;
- int i;
- int ncandidates;
- int nbestMatch,
- nmatch;
- CATEGORY slot_category[FUNC_MAX_ARGS],
- current_category;
- bool slot_has_preferred_type[FUNC_MAX_ARGS];
- bool resolved_unknowns;
-
- /*
- * Run through all candidates and keep those with the most matches on
- * exact types. Keep all candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID &&
- current_typeids[i] == input_typeids[i])
- nmatch++;
- }
-
- /* take this one as the best choice so far? */
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- /* no worse than the last choice, so keep this one too? */
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- /* otherwise, don't bother keeping this one... */
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates;
-
- /*
- * Still too many candidates? Run through all candidates and keep
- * those with the most matches on exact types + binary-compatible
- * types. Keep all candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- {
- if (IsBinaryCompatible(current_typeids[i], input_typeids[i]))
- nmatch++;
- }
- }
-
- /* take this one as the best choice so far? */
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- /* no worse than the last choice, so keep this one too? */
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- /* otherwise, don't bother keeping this one... */
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates;
-
- /*
- * Still too many candidates? Now look for candidates which are
- * preferred types at the args that will require coercion. Keep all
- * candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- {
- current_category = TypeCategory(current_typeids[i]);
- if (current_typeids[i] == input_typeids[i] ||
- IsPreferredType(current_category, current_typeids[i]))
- nmatch++;
- }
- }
-
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates;
-
- /*
- * Still too many candidates? Try assigning types for the unknown
- * columns.
- *
- * We do this by examining each unknown argument position to see if we
- * can determine a "type category" for it. If any candidate has an
- * input datatype of STRING category, use STRING category (this bias
- * towards STRING is appropriate since unknown-type literals look like
- * strings). Otherwise, if all the candidates agree on the type
- * category of this argument position, use that category. Otherwise,
- * fail because we cannot determine a category.
- *
- * If we are able to determine a type category, also notice whether any
- * of the candidates takes a preferred datatype within the category.
- *
- * Having completed this examination, remove candidates that accept the
- * wrong category at any unknown position. Also, if at least one
- * candidate accepted a preferred type at a position, remove
- * candidates that accept non-preferred types.
- *
- * If we are down to one candidate at the end, we win.
- */
- resolved_unknowns = false;
- for (i = 0; i < nargs; i++)
- {
- bool have_conflict;
-
- if (input_typeids[i] != UNKNOWNOID)
- continue;
- resolved_unknowns = true; /* assume we can do it */
- slot_category[i] = INVALID_TYPE;
- slot_has_preferred_type[i] = false;
- have_conflict = false;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- current_type = current_typeids[i];
- current_category = TypeCategory(current_type);
- if (slot_category[i] == INVALID_TYPE)
- {
- /* first candidate */
- slot_category[i] = current_category;
- slot_has_preferred_type[i] =
- IsPreferredType(current_category, current_type);
- }
- else if (current_category == slot_category[i])
- {
- /* more candidates in same category */
- slot_has_preferred_type[i] |=
- IsPreferredType(current_category, current_type);
- }
- else
- {
- /* category conflict! */
- if (current_category == STRING_TYPE)
- {
- /* STRING always wins if available */
- slot_category[i] = current_category;
- slot_has_preferred_type[i] =
- IsPreferredType(current_category, current_type);
- }
- else
- {
- /*
- * Remember conflict, but keep going (might find
- * STRING)
- */
- have_conflict = true;
- }
- }
- }
- if (have_conflict && slot_category[i] != STRING_TYPE)
- {
- /* Failed to resolve category conflict at this position */
- resolved_unknowns = false;
- break;
- }
- }
-
- if (resolved_unknowns)
- {
- /* Strip non-matching candidates */
- ncandidates = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- bool keepit = true;
-
- current_typeids = current_candidate->args;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- continue;
- current_type = current_typeids[i];
- current_category = TypeCategory(current_type);
- if (current_category != slot_category[i])
- {
- keepit = false;
- break;
- }
- if (slot_has_preferred_type[i] &&
- !IsPreferredType(current_category, current_type))
- {
- keepit = false;
- break;
- }
- }
- if (keepit)
- {
- /* keep this candidate */
- last_candidate = current_candidate;
- ncandidates++;
- }
- else
- {
- /* forget this candidate */
- if (last_candidate)
- last_candidate->next = current_candidate->next;
- else
- candidates = current_candidate->next;
- }
- }
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
- }
-
- if (ncandidates == 1)
- return candidates;
-
- return NULL; /* failed to determine a unique candidate */
-} /* func_select_candidate() */
-
-
-/* func_get_detail()
- *
- * Find the named function in the system catalogs.
- *
- * Attempt to find the named function in the system catalogs with
- * arguments exactly as specified, so that the normal case
- * (exact match) is as quick as possible.
- *
- * If an exact match isn't found:
- * 1) check for possible interpretation as a trivial type coercion
- * 2) get a vector of all possible input arg type arrays constructed
- * from the superclasses of the original input arg types
- * 3) get a list of all possible argument type arrays to the function
- * with given name and number of arguments
- * 4) for each input arg type array from vector #1:
- * a) find how many of the function arg type arrays from list #2
- * it can be coerced to
- * b) if the answer is one, we have our function
- * c) if the answer is more than one, attempt to resolve the conflict
- * d) if the answer is zero, try the next array from vector #1
- *
- * Note: we rely primarily on nargs/argtypes as the argument description.
- * The actual expression node list is passed in fargs so that we can check
- * for type coercion of a constant. Some callers pass fargs == NIL
- * indicating they don't want that check made.
- */
-FuncDetailCode
-func_get_detail(List *funcname,
- List *fargs,
- int nargs,
- Oid *argtypes,
- Oid *funcid, /* return value */
- Oid *rettype, /* return value */
- bool *retset, /* return value */
- Oid **true_typeids) /* return value */
-{
- FuncCandidateList function_typeids;
- FuncCandidateList best_candidate;
-
- /* Get list of possible candidates from namespace search */
- function_typeids = FuncnameGetCandidates(funcname, nargs);
-
- /*
- * See if there is an exact match
- */
- for (best_candidate = function_typeids;
- best_candidate != NULL;
- best_candidate = best_candidate->next)
- {
- if (memcmp(argtypes, best_candidate->args, nargs * sizeof(Oid)) == 0)
- break;
- }
-
- if (best_candidate == NULL)
- {
- /*
- * If we didn't find an exact match, next consider the possibility
- * that this is really a type-coercion request: a single-argument
- * function call where the function name is a type name. If so,
- * and if we can do the coercion trivially (no run-time function
- * call needed), then go ahead and treat the "function call" as a
- * coercion. This interpretation needs to be given higher
- * priority than interpretations involving a type coercion
- * followed by a function call, otherwise we can produce
- * surprising results. For example, we want "text(varchar)" to be
- * interpreted as a trivial coercion, not as "text(name(varchar))"
- * which the code below this point is entirely capable of
- * selecting.
- *
- * "Trivial" coercions are ones that involve binary-compatible types
- * and ones that are coercing a previously-unknown-type literal
- * constant to a specific type.
- *
- * NB: it's important that this code stays in sync with what
- * coerce_type can do, because the caller will try to apply
- * coerce_type if we return FUNCDETAIL_COERCION. If we return
- * that result for something coerce_type can't handle, we'll cause
- * infinite recursion between this module and coerce_type!
- */
- if (nargs == 1 && fargs != NIL)
- {
- Oid targetType;
- TypeName *tn = makeNode(TypeName);
-
- tn->names = funcname;
- tn->typmod = -1;
- targetType = LookupTypeName(tn);
- if (OidIsValid(targetType) &&
- !ISCOMPLEX(targetType))
- {
- Oid sourceType = argtypes[0];
- Node *arg1 = lfirst(fargs);
-
- if ((sourceType == UNKNOWNOID && IsA(arg1, Const)) ||
- IsBinaryCompatible(sourceType, targetType))
- {
- /* Yup, it's a type coercion */
- *funcid = InvalidOid;
- *rettype = targetType;
- *retset = false;
- *true_typeids = argtypes;
- return FUNCDETAIL_COERCION;
- }
- }
- }
-
- /*
- * didn't find an exact match, so now try to match up
- * candidates...
- */
- if (function_typeids != NULL)
- {
- Oid **input_typeid_vector = NULL;
- Oid *current_input_typeids;
-
- /*
- * First we will search with the given argtypes, then with
- * variants based on replacing complex types with their
- * inheritance ancestors. Stop as soon as any match is found.
- */
- current_input_typeids = argtypes;
-
- do
- {
- FuncCandidateList current_function_typeids;
- int ncandidates;
-
- ncandidates = match_argtypes(nargs, current_input_typeids,
- function_typeids,
- &current_function_typeids);
-
- /* one match only? then run with it... */
- if (ncandidates == 1)
- {
- best_candidate = current_function_typeids;
- break;
- }
-
- /*
- * multiple candidates? then better decide or throw an
- * error...
- */
- if (ncandidates > 1)
- {
- best_candidate = func_select_candidate(nargs,
- current_input_typeids,
- current_function_typeids);
-
- /*
- * If we were able to choose a best candidate, we're
- * done. Otherwise, ambiguous function call, so fail
- * by exiting loop with best_candidate still NULL.
- * Either way, we're outta here.
- */
- break;
- }
-
- /*
- * No match here, so try the next inherited type vector.
- * First time through, we need to compute the list of
- * vectors.
- */
- if (input_typeid_vector == NULL)
- input_typeid_vector = argtype_inherit(nargs, argtypes);
-
- current_input_typeids = *input_typeid_vector++;
- }
- while (current_input_typeids != NULL);
- }
- }
-
- if (best_candidate)
- {
- HeapTuple ftup;
- Form_pg_proc pform;
- FuncDetailCode result;
-
- *funcid = best_candidate->oid;
- *true_typeids = best_candidate->args;
-
- ftup = SearchSysCache(PROCOID,
- ObjectIdGetDatum(best_candidate->oid),
- 0, 0, 0);
- if (!HeapTupleIsValid(ftup)) /* should not happen */
- elog(ERROR, "function %u not found", best_candidate->oid);
- pform = (Form_pg_proc) GETSTRUCT(ftup);
- *rettype = pform->prorettype;
- *retset = pform->proretset;
- result = pform->proisagg ? FUNCDETAIL_AGGREGATE : FUNCDETAIL_NORMAL;
- ReleaseSysCache(ftup);
- return result;
- }
-
- return FUNCDETAIL_NOTFOUND;
-} /* func_get_detail() */
-
-/*
- * argtype_inherit() -- Construct an argtype vector reflecting the
- * inheritance properties of the supplied argv.
- *
- * This function is used to disambiguate among functions with the
- * same name but different signatures. It takes an array of input
- * type ids. For each type id in the array that's a complex type
- * (a class), it walks up the inheritance tree, finding all
- * superclasses of that type. A vector of new Oid type arrays
- * is returned to the caller, reflecting the structure of the
- * inheritance tree above the supplied arguments.
- *
- * The order of this vector is as follows: all superclasses of the
- * rightmost complex class are explored first. The exploration
- * continues from right to left. This policy means that we favor
- * keeping the leftmost argument type as low in the inheritance tree
- * as possible. This is intentional; it is exactly what we need to
- * do for method dispatch. The last type array we return is all
- * zeroes. This will match any functions for which return types are
- * not defined. There are lots of these (mostly builtins) in the
- * catalogs.
- */
-static Oid **
-argtype_inherit(int nargs, Oid *argtypes)
-{
- Oid relid;
- int i;
- InhPaths arginh[FUNC_MAX_ARGS];
-
- for (i = 0; i < FUNC_MAX_ARGS; i++)
- {
- if (i < nargs)
- {
- arginh[i].self = argtypes[i];
- if ((relid = typeidTypeRelid(argtypes[i])) != InvalidOid)
- arginh[i].nsupers = find_inheritors(relid, &(arginh[i].supervec));
- else
- {
- arginh[i].nsupers = 0;
- arginh[i].supervec = (Oid *) NULL;
- }
- }
- else
- {
- arginh[i].self = InvalidOid;
- arginh[i].nsupers = 0;
- arginh[i].supervec = (Oid *) NULL;
- }
- }
-
- /* return an ordered cross-product of the classes involved */
- return gen_cross_product(arginh, nargs);
-}
-
-static int
-find_inheritors(Oid relid, Oid **supervec)
-{
- Relation inhrel;
- HeapScanDesc inhscan;
- ScanKeyData skey;
- HeapTuple inhtup;
- Oid *relidvec;
- int nvisited;
- List *visited,
- *queue;
- List *elt;
- bool newrelid;
-
- nvisited = 0;
- queue = NIL;
- visited = NIL;
-
- inhrel = heap_openr(InheritsRelationName, AccessShareLock);
-
- /*
- * Use queue to do a breadth-first traversal of the inheritance graph
- * from the relid supplied up to the root. At the top of the loop,
- * relid is the OID of the reltype to check next, queue is the list of
- * pending rels to check after this one, and visited is the list of
- * relids we need to output.
- */
- do
- {
- /* find all types this relid inherits from, and add them to queue */
-
- ScanKeyEntryInitialize(&skey, 0x0, Anum_pg_inherits_inhrelid,
- F_OIDEQ,
- ObjectIdGetDatum(relid));
-
- inhscan = heap_beginscan(inhrel, SnapshotNow, 1, &skey);
-
- while ((inhtup = heap_getnext(inhscan, ForwardScanDirection)) != NULL)
- {
- Form_pg_inherits inh = (Form_pg_inherits) GETSTRUCT(inhtup);
-
- queue = lappendi(queue, inh->inhparent);
- }
-
- heap_endscan(inhscan);
-
- /* pull next unvisited relid off the queue */
-
- newrelid = false;
- while (queue != NIL)
- {
- relid = lfirsti(queue);
- queue = lnext(queue);
- if (!intMember(relid, visited))
- {
- newrelid = true;
- break;
- }
- }
-
- if (newrelid)
- {
- visited = lappendi(visited, relid);
- nvisited++;
- }
- } while (newrelid);
-
- heap_close(inhrel, AccessShareLock);
-
- if (nvisited > 0)
- {
- relidvec = (Oid *) palloc(nvisited * sizeof(Oid));
- *supervec = relidvec;
-
- foreach(elt, visited)
- {
- /* return the type id, rather than the relation id */
- *relidvec++ = get_rel_type_id((Oid) lfirsti(elt));
- }
- }
- else
- *supervec = (Oid *) NULL;
-
- freeList(visited);
-
- /*
- * there doesn't seem to be any equally easy way to release the queue
- * list cells, but since they're palloc'd space it's not critical.
- */
-
- return nvisited;
-}
-
-static Oid **
-gen_cross_product(InhPaths *arginh, int nargs)
-{
- int nanswers;
- Oid **result,
- **iter;
- Oid *oneres;
- int i,
- j;
- int cur[FUNC_MAX_ARGS];
-
- nanswers = 1;
- for (i = 0; i < nargs; i++)
- {
- nanswers *= (arginh[i].nsupers + 2);
- cur[i] = 0;
- }
-
- iter = result = (Oid **) palloc(sizeof(Oid *) * nanswers);
-
- /* compute the cross product from right to left */
- for (;;)
- {
- oneres = (Oid *) palloc(FUNC_MAX_ARGS * sizeof(Oid));
- MemSet(oneres, 0, FUNC_MAX_ARGS * sizeof(Oid));
-
- for (i = nargs - 1; i >= 0 && cur[i] > arginh[i].nsupers; i--)
- continue;
-
- /* if we're done, terminate with NULL pointer */
- if (i < 0)
- {
- *iter = NULL;
- return result;
- }
-
- /* no, increment this column and zero the ones after it */
- cur[i] = cur[i] + 1;
- for (j = nargs - 1; j > i; j--)
- cur[j] = 0;
-
- for (i = 0; i < nargs; i++)
- {
- if (cur[i] == 0)
- oneres[i] = arginh[i].self;
- else if (cur[i] > arginh[i].nsupers)
- oneres[i] = 0; /* wild card */
- else
- oneres[i] = arginh[i].supervec[cur[i] - 1];
- }
-
- *iter++ = oneres;
- }
-}
-
-
-/*
- * Given two type OIDs, determine whether the first is a complex type
- * (class type) that inherits from the second.
- */
-bool
-typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
-{
- Oid relid;
- Oid *supervec;
- int nsupers,
- i;
- bool result;
-
- if (!ISCOMPLEX(subclassTypeId) || !ISCOMPLEX(superclassTypeId))
- return false;
- relid = typeidTypeRelid(subclassTypeId);
- if (relid == InvalidOid)
- return false;
- nsupers = find_inheritors(relid, &supervec);
- result = false;
- for (i = 0; i < nsupers; i++)
- {
- if (supervec[i] == superclassTypeId)
- {
- result = true;
- break;
- }
- }
- if (supervec)
- pfree(supervec);
- return result;
-}
-
-
-/* make_arguments()
- * Given the number and types of arguments to a function, and the
- * actual arguments and argument types, do the necessary typecasting.
- */
-static void
-make_arguments(ParseState *pstate,
- int nargs,
- List *fargs,
- Oid *input_typeids,
- Oid *function_typeids)
-{
- List *current_fargs;
- int i;
-
- for (i = 0, current_fargs = fargs;
- i < nargs;
- i++, current_fargs = lnext(current_fargs))
- {
- /* types don't match? then force coercion using a function call... */
- if (input_typeids[i] != function_typeids[i])
- {
- lfirst(current_fargs) = coerce_type(pstate,
- lfirst(current_fargs),
- input_typeids[i],
- function_typeids[i], -1,
- false);
- }
- }
-}
-
-/*
- * setup_field_select
- * Build a FieldSelect node that says which attribute to project to.
- * This routine is called by ParseFuncOrColumn() when we have found
- * a projection on a function result or parameter.
- */
-static FieldSelect *
-setup_field_select(Node *input, char *attname, Oid relid)
-{
- FieldSelect *fselect = makeNode(FieldSelect);
- AttrNumber attno;
-
- attno = get_attnum(relid, attname);
-
- fselect->arg = input;
- fselect->fieldnum = attno;
- fselect->resulttype = get_atttype(relid, attno);
- fselect->resulttypmod = get_atttypmod(relid, attno);
-
- return fselect;
-}
-
-/*
- * ParseComplexProjection -
- * handles function calls with a single argument that is of complex type.
- * If the function call is actually a column projection, return a suitably
- * transformed expression tree. If not, return NULL.
- *
- * NB: argument is expected to be transformed already, ie, not a RangeVar.
- */
-static Node *
-ParseComplexProjection(ParseState *pstate,
- char *funcname,
- Node *first_arg)
-{
- Oid argtype = exprType(first_arg);
- Oid argrelid;
- AttrNumber attnum;
- FieldSelect *fselect;
-
- argrelid = typeidTypeRelid(argtype);
- if (!argrelid)
- return NULL; /* probably should not happen */
- attnum = get_attnum(argrelid, funcname);
- if (attnum == InvalidAttrNumber)
- return NULL; /* funcname does not match any column */
-
- /*
- * Check for special cases where we don't want to return a FieldSelect.
- */
- switch (nodeTag(first_arg))
- {
- case T_Var:
- {
- Var *var = (Var *) first_arg;
-
- /*
- * If the Var is a whole-row tuple, we can just replace it
- * with a simple Var reference.
- */
- if (var->varattno == InvalidAttrNumber)
- {
- Oid vartype;
- int32 vartypmod;
-
- get_atttypetypmod(argrelid, attnum,
- &vartype, &vartypmod);
-
- return (Node *) makeVar(var->varno,
- attnum,
- vartype,
- vartypmod,
- var->varlevelsup);
- }
- break;
- }
- default:
- break;
- }
-
- /* Else generate a FieldSelect expression */
- fselect = setup_field_select(first_arg, funcname, argrelid);
- return (Node *) fselect;
-}
-
-/*
- * Error message when function lookup fails that gives details of the
- * argument types
- */
-void
-func_error(const char *caller, List *funcname,
- int nargs, const Oid *argtypes,
- const char *msg)
-{
- StringInfoData argbuf;
- int i;
-
- initStringInfo(&argbuf);
-
- for (i = 0; i < nargs; i++)
- {
- if (i)
- appendStringInfo(&argbuf, ", ");
- if (OidIsValid(argtypes[i]))
- appendStringInfo(&argbuf, format_type_be(argtypes[i]));
- else
- appendStringInfo(&argbuf, "opaque");
- }
-
- if (caller == NULL)
- {
- elog(ERROR, "Function %s(%s) does not exist%s%s",
- NameListToString(funcname), argbuf.data,
- ((msg != NULL) ? "\n\t" : ""), ((msg != NULL) ? msg : ""));
- }
- else
- {
- elog(ERROR, "%s: function %s(%s) does not exist%s%s",
- caller, NameListToString(funcname), argbuf.data,
- ((msg != NULL) ? "\n\t" : ""), ((msg != NULL) ? msg : ""));
- }
-}
-
-/*
- * find_aggregate_func
- * Convenience routine to check that a function exists and is an
- * aggregate.
- *
- * Note: basetype is InvalidOid if we are looking for an aggregate on
- * all types.
- */
-Oid
-find_aggregate_func(const char *caller, List *aggname, Oid basetype)
-{
- Oid oid;
- HeapTuple ftup;
- Form_pg_proc pform;
-
- oid = LookupFuncName(aggname, 1, &basetype);
-
- if (!OidIsValid(oid))
- {
- if (basetype == InvalidOid)
- elog(ERROR, "%s: aggregate %s(*) does not exist",
- caller, NameListToString(aggname));
- else
- elog(ERROR, "%s: aggregate %s(%s) does not exist",
- caller, NameListToString(aggname),
- format_type_be(basetype));
- }
-
- /* Make sure it's an aggregate */
- ftup = SearchSysCache(PROCOID,
- ObjectIdGetDatum(oid),
- 0, 0, 0);
- if (!HeapTupleIsValid(ftup)) /* should not happen */
- elog(ERROR, "function %u not found", oid);
- pform = (Form_pg_proc) GETSTRUCT(ftup);
-
- if (!pform->proisagg)
- {
- if (basetype == InvalidOid)
- elog(ERROR, "%s: function %s(*) is not an aggregate",
- caller, NameListToString(aggname));
- else
- elog(ERROR, "%s: function %s(%s) is not an aggregate",
- caller, NameListToString(aggname),
- format_type_be(basetype));
- }
-
- ReleaseSysCache(ftup);
-
- return oid;
-}
-
-/*
- * LookupFuncName
- * Given a possibly-qualified function name and a set of argument types,
- * look up the function. Returns InvalidOid if no such function.
- *
- * If the function name is not schema-qualified, it is sought in the current
- * namespace search path.
- */
-Oid
-LookupFuncName(List *funcname, int nargs, const Oid *argtypes)
-{
- FuncCandidateList clist;
-
- clist = FuncnameGetCandidates(funcname, nargs);
-
- while (clist)
- {
- if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
- return clist->oid;
- clist = clist->next;
- }
-
- return InvalidOid;
-}
-
-/*
- * LookupFuncNameTypeNames
- * Like LookupFuncName, but the argument types are specified by a
- * list of TypeName nodes. Also, if we fail to find the function
- * and caller is not NULL, then an error is reported via func_error.
- *
- * "opaque" is accepted as a typename only if opaqueOK is true.
- */
-Oid
-LookupFuncNameTypeNames(List *funcname, List *argtypes, bool opaqueOK,
- const char *caller)
-{
- Oid funcoid;
- Oid argoids[FUNC_MAX_ARGS];
- int argcount;
- int i;
-
- MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid));
- argcount = length(argtypes);
- if (argcount > FUNC_MAX_ARGS)
- elog(ERROR, "functions cannot have more than %d arguments",
- FUNC_MAX_ARGS);
-
- for (i = 0; i < argcount; i++)
- {
- TypeName *t = (TypeName *) lfirst(argtypes);
-
- argoids[i] = LookupTypeName(t);
- if (!OidIsValid(argoids[i]))
- {
- char *typnam = TypeNameToString(t);
-
- if (opaqueOK && strcmp(typnam, "opaque") == 0)
- argoids[i] = InvalidOid;
- else
- elog(ERROR, "Type \"%s\" does not exist", typnam);
- }
-
- argtypes = lnext(argtypes);
- }
-
- funcoid = LookupFuncName(funcname, argcount, argoids);
-
- if (!OidIsValid(funcoid) && caller != NULL)
- func_error(caller, funcname, argcount, argoids, NULL);
-
- return funcoid;
-}
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
deleted file mode 100644
index 652ab54d2a9..00000000000
--- a/src/backend/parser/parse_node.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_node.c
- * various routines that make nodes for query plans
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.66 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <float.h>
-
-#include "access/heapam.h"
-#include "catalog/pg_operator.h"
-#include "catalog/pg_type.h"
-#include "fmgr.h"
-#include "nodes/makefuncs.h"
-#include "parser/parsetree.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_node.h"
-#include "parser/parse_oper.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_target.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/varbit.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-static bool fitsInFloat(Value *value);
-
-
-/* make_parsestate()
- * Allocate and initialize a new ParseState.
- * The CALLER is responsible for freeing the ParseState* returned.
- */
-ParseState *
-make_parsestate(ParseState *parentParseState)
-{
- ParseState *pstate;
-
- pstate = palloc(sizeof(ParseState));
- MemSet(pstate, 0, sizeof(ParseState));
-
- pstate->parentParseState = parentParseState;
- pstate->p_last_resno = 1;
-
- return pstate;
-}
-
-
-/* make_operand()
- * Ensure argument type match by forcing conversion of constants.
- */
-Node *
-make_operand(Node *tree, Oid orig_typeId, Oid target_typeId)
-{
- Node *result;
-
- if (tree != NULL)
- {
- /* must coerce? */
- if (target_typeId != orig_typeId)
- result = coerce_type(NULL, tree, orig_typeId, target_typeId, -1,
- false);
- else
- result = tree;
- }
- else
- {
- /* otherwise, this is a NULL value */
- result = (Node *) makeNullConst(target_typeId);
- }
-
- return result;
-} /* make_operand() */
-
-
-/* make_op()
- * Operator construction.
- *
- * Transform operator expression ensuring type compatibility.
- * This is where some type conversion happens.
- */
-Expr *
-make_op(List *opname, Node *ltree, Node *rtree)
-{
- Oid ltypeId,
- rtypeId;
- Operator tup;
- Form_pg_operator opform;
- Oper *newop;
- Node *left,
- *right;
- Expr *result;
-
- ltypeId = (ltree == NULL) ? UNKNOWNOID : exprType(ltree);
- rtypeId = (rtree == NULL) ? UNKNOWNOID : exprType(rtree);
-
- /* right operator? */
- if (rtree == NULL)
- {
- tup = right_oper(opname, ltypeId, false);
- opform = (Form_pg_operator) GETSTRUCT(tup);
- left = make_operand(ltree, ltypeId, opform->oprleft);
- right = NULL;
- }
-
- /* left operator? */
- else if (ltree == NULL)
- {
- tup = left_oper(opname, rtypeId, false);
- opform = (Form_pg_operator) GETSTRUCT(tup);
- right = make_operand(rtree, rtypeId, opform->oprright);
- left = NULL;
- }
-
- /* otherwise, binary operator */
- else
- {
- tup = oper(opname, ltypeId, rtypeId, false);
- opform = (Form_pg_operator) GETSTRUCT(tup);
- left = make_operand(ltree, ltypeId, opform->oprleft);
- right = make_operand(rtree, rtypeId, opform->oprright);
- }
-
- newop = makeOper(oprid(tup), /* opno */
- InvalidOid, /* opid */
- opform->oprresult, /* opresulttype */
- get_func_retset(opform->oprcode)); /* opretset */
-
- result = makeNode(Expr);
- result->typeOid = opform->oprresult;
- result->opType = OP_EXPR;
- result->oper = (Node *) newop;
-
- if (!left)
- result->args = makeList1(right);
- else if (!right)
- result->args = makeList1(left);
- else
- result->args = makeList2(left, right);
-
- ReleaseSysCache(tup);
-
- return result;
-} /* make_op() */
-
-
-/*
- * make_var
- * Build a Var node for an attribute identified by RTE and attrno
- */
-Var *
-make_var(ParseState *pstate, RangeTblEntry *rte, int attrno)
-{
- int vnum,
- sublevels_up;
- Oid vartypeid;
- int32 type_mod;
-
- vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
- get_rte_attribute_type(rte, attrno, &vartypeid, &type_mod);
- return makeVar(vnum, attrno, vartypeid, type_mod, sublevels_up);
-}
-
-/*
- * transformArraySubscripts()
- * Transform array subscripting. This is used for both
- * array fetch and array assignment.
- *
- * In an array fetch, we are given a source array value and we produce an
- * expression that represents the result of extracting a single array element
- * or an array slice.
- *
- * In an array assignment, we are given a destination array value plus a
- * source value that is to be assigned to a single element or a slice of
- * that array. We produce an expression that represents the new array value
- * with the source data inserted into the right part of the array.
- *
- * pstate Parse state
- * arrayBase Already-transformed expression for the array as a whole
- * (may be NULL if we are handling an INSERT)
- * arrayType OID of array's datatype
- * indirection Untransformed list of subscripts (must not be NIL)
- * forceSlice If true, treat subscript as array slice in all cases
- * assignFrom NULL for array fetch, else transformed expression for source.
- */
-ArrayRef *
-transformArraySubscripts(ParseState *pstate,
- Node *arrayBase,
- Oid arrayType,
- List *indirection,
- bool forceSlice,
- Node *assignFrom)
-{
- Oid elementType,
- resultType;
- HeapTuple type_tuple_array,
- type_tuple_element;
- Form_pg_type type_struct_array,
- type_struct_element;
- bool isSlice = forceSlice;
- List *upperIndexpr = NIL;
- List *lowerIndexpr = NIL;
- List *idx;
- ArrayRef *aref;
-
- /* Get the type tuple for the array */
- type_tuple_array = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(arrayType),
- 0, 0, 0);
- if (!HeapTupleIsValid(type_tuple_array))
- elog(ERROR, "transformArraySubscripts: Cache lookup failed for array type %u",
- arrayType);
- type_struct_array = (Form_pg_type) GETSTRUCT(type_tuple_array);
-
- elementType = type_struct_array->typelem;
- if (elementType == InvalidOid)
- elog(ERROR, "transformArraySubscripts: type %s is not an array",
- NameStr(type_struct_array->typname));
-
- /* Get the type tuple for the array element type */
- type_tuple_element = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(elementType),
- 0, 0, 0);
- if (!HeapTupleIsValid(type_tuple_element))
- elog(ERROR, "transformArraySubscripts: Cache lookup failed for array element type %u",
- elementType);
- type_struct_element = (Form_pg_type) GETSTRUCT(type_tuple_element);
-
- /*
- * A list containing only single subscripts refers to a single array
- * element. If any of the items are double subscripts (lower:upper),
- * then the subscript expression means an array slice operation. In
- * this case, we supply a default lower bound of 1 for any items that
- * contain only a single subscript. The forceSlice parameter forces us
- * to treat the operation as a slice, even if no lower bounds are
- * mentioned. Otherwise, we have to prescan the indirection list to
- * see if there are any double subscripts.
- */
- if (!isSlice)
- {
- foreach(idx, indirection)
- {
- A_Indices *ai = (A_Indices *) lfirst(idx);
-
- if (ai->lidx != NULL)
- {
- isSlice = true;
- break;
- }
- }
- }
-
- /*
- * The type represented by the subscript expression is the element
- * type if we are fetching a single element, but it is the same as the
- * array type if we are fetching a slice or storing.
- */
- if (isSlice || assignFrom != NULL)
- resultType = arrayType;
- else
- resultType = elementType;
-
- /*
- * Transform the subscript expressions.
- */
- foreach(idx, indirection)
- {
- A_Indices *ai = (A_Indices *) lfirst(idx);
- Node *subexpr;
-
- if (isSlice)
- {
- if (ai->lidx)
- {
- subexpr = transformExpr(pstate, ai->lidx);
- /* If it's not int4 already, try to coerce */
- subexpr = CoerceTargetExpr(pstate, subexpr, exprType(subexpr),
- INT4OID, -1, false);
- if (subexpr == NULL)
- elog(ERROR, "array index expressions must be integers");
- }
- else
- {
- /* Make a constant 1 */
- subexpr = (Node *) makeConst(INT4OID,
- sizeof(int32),
- Int32GetDatum(1),
- false,
- true, /* pass by value */
- false,
- false);
- }
- lowerIndexpr = lappend(lowerIndexpr, subexpr);
- }
- subexpr = transformExpr(pstate, ai->uidx);
- /* If it's not int4 already, try to coerce */
- subexpr = CoerceTargetExpr(pstate, subexpr, exprType(subexpr),
- INT4OID, -1, false);
- if (subexpr == NULL)
- elog(ERROR, "array index expressions must be integers");
- upperIndexpr = lappend(upperIndexpr, subexpr);
- }
-
- /*
- * If doing an array store, coerce the source value to the right type.
- */
- if (assignFrom != NULL)
- {
- Oid typesource = exprType(assignFrom);
- Oid typeneeded = isSlice ? arrayType : elementType;
-
- if (typesource != InvalidOid)
- {
- if (typesource != typeneeded)
- {
- /* XXX fixme: need to get the array's atttypmod? */
- assignFrom = CoerceTargetExpr(pstate, assignFrom,
- typesource, typeneeded,
- -1, false);
- if (assignFrom == NULL)
- elog(ERROR, "Array assignment requires type '%s'"
- " but expression is of type '%s'"
- "\n\tYou will need to rewrite or cast the expression",
- format_type_be(typeneeded),
- format_type_be(typesource));
- }
- }
- }
-
- /*
- * Ready to build the ArrayRef node.
- */
- aref = makeNode(ArrayRef);
- aref->refattrlength = type_struct_array->typlen;
- aref->refelemlength = type_struct_element->typlen;
- aref->refelemtype = resultType; /* XXX should save element type
- * too */
- aref->refelembyval = type_struct_element->typbyval;
- aref->refupperindexpr = upperIndexpr;
- aref->reflowerindexpr = lowerIndexpr;
- aref->refexpr = arrayBase;
- aref->refassgnexpr = assignFrom;
-
- ReleaseSysCache(type_tuple_array);
- ReleaseSysCache(type_tuple_element);
-
- return aref;
-}
-
-/*
- * make_const
- *
- * Convert a Value node (as returned by the grammar) to a Const node
- * of the "natural" type for the constant. Note that this routine is
- * only used when there is no explicit cast for the constant, so we
- * have to guess what type is wanted.
- *
- * For string literals we produce a constant of type UNKNOWN ---- whose
- * representation is the same as text, but it indicates to later type
- * resolution that we're not sure that it should be considered text.
- * Explicit "NULL" constants are also typed as UNKNOWN.
- *
- * For integers and floats we produce int4, float8, or numeric depending
- * on the value of the number. XXX In some cases it would be nice to take
- * context into account when determining the type to convert to, but in
- * other cases we can't delay the type choice. One possibility is to invent
- * a dummy type "UNKNOWNNUMERIC" that's treated similarly to UNKNOWN;
- * that would allow us to do the right thing in examples like a simple
- * INSERT INTO table (numericcolumn) VALUES (1.234), since we wouldn't
- * have to resolve the unknown type until we knew the destination column
- * type. On the other hand UNKNOWN has considerable problems of its own.
- * We would not like "SELECT 1.2 + 3.4" to claim it can't choose a type.
- */
-Const *
-make_const(Value *value)
-{
- Datum val;
- Oid typeid;
- int typelen;
- bool typebyval;
- Const *con;
-
- switch (nodeTag(value))
- {
- case T_Integer:
- val = Int32GetDatum(intVal(value));
-
- typeid = INT4OID;
- typelen = sizeof(int32);
- typebyval = true;
- break;
-
- case T_Float:
- if (fitsInFloat(value))
- {
- val = Float8GetDatum(floatVal(value));
-
- typeid = FLOAT8OID;
- typelen = sizeof(float8);
- typebyval = false; /* XXX might change someday */
- }
- else
- {
- val = DirectFunctionCall3(numeric_in,
- CStringGetDatum(strVal(value)),
- ObjectIdGetDatum(InvalidOid),
- Int32GetDatum(-1));
-
- typeid = NUMERICOID;
- typelen = -1; /* variable len */
- typebyval = false;
- }
- break;
-
- case T_String:
- val = DirectFunctionCall1(unknownin,
- CStringGetDatum(strVal(value)));
-
- typeid = UNKNOWNOID; /* will be coerced later */
- typelen = -1; /* variable len */
- typebyval = false;
- break;
-
- case T_BitString:
- val = DirectFunctionCall3(bit_in,
- CStringGetDatum(strVal(value)),
- ObjectIdGetDatum(InvalidOid),
- Int32GetDatum(-1));
- typeid = BITOID;
- typelen = -1;
- typebyval = false;
- break;
-
- default:
- elog(WARNING, "make_const: unknown type %d", nodeTag(value));
- /* FALLTHROUGH */
-
- case T_Null:
- /* return a null const */
- con = makeConst(UNKNOWNOID,
- -1,
- (Datum) NULL,
- true,
- false,
- false,
- false);
- return con;
- }
-
- con = makeConst(typeid,
- typelen,
- val,
- false,
- typebyval,
- false, /* not a set */
- false); /* not coerced */
-
- return con;
-}
-
-/*
- * Decide whether a T_Float value fits in float8, or must be treated as
- * type "numeric". We check the number of digits and check for overflow/
- * underflow. (With standard compilation options, Postgres' NUMERIC type
- * can handle decimal exponents up to 1000, considerably more than most
- * implementations of float8, so this is a sensible test.)
- */
-static bool
-fitsInFloat(Value *value)
-{
- const char *ptr;
- int ndigits;
- char *endptr;
-
- /*
- * Count digits, ignoring leading zeroes (but not trailing zeroes).
- * DBL_DIG is the maximum safe number of digits for "double".
- */
- ptr = strVal(value);
- while (*ptr == '+' || *ptr == '-' || *ptr == '0' || *ptr == '.')
- ptr++;
- ndigits = 0;
- for (; *ptr; ptr++)
- {
- if (isdigit((unsigned char) *ptr))
- ndigits++;
- else if (*ptr == 'e' || *ptr == 'E')
- break; /* don't count digits in exponent */
- }
- if (ndigits > DBL_DIG)
- return false;
-
- /*
- * Use strtod() to check for overflow/underflow.
- */
- errno = 0;
- (void) strtod(strVal(value), &endptr);
- if (*endptr != '\0' || errno != 0)
- return false;
-
- return true;
-}
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c
deleted file mode 100644
index 663e83831b3..00000000000
--- a/src/backend/parser/parse_oper.c
+++ /dev/null
@@ -1,935 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_oper.c
- * handle operator things for parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.57 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "access/genam.h"
-#include "access/heapam.h"
-#include "catalog/catname.h"
-#include "catalog/indexing.h"
-#include "catalog/namespace.h"
-#include "catalog/pg_operator.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_func.h"
-#include "parser/parse_oper.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/fmgroids.h"
-#include "utils/syscache.h"
-
-static Oid binary_oper_exact(Oid arg1, Oid arg2,
- FuncCandidateList candidates);
-static Oid oper_select_candidate(int nargs, Oid *input_typeids,
- FuncCandidateList candidates);
-static void op_error(List *op, Oid arg1, Oid arg2);
-static void unary_op_error(List *op, Oid arg, bool is_left_op);
-
-
-/*
- * LookupOperName
- * Given a possibly-qualified operator name and exact input datatypes,
- * look up the operator. Returns InvalidOid if no such operator.
- *
- * Pass oprleft = InvalidOid for a prefix op, oprright = InvalidOid for
- * a postfix op.
- *
- * If the operator name is not schema-qualified, it is sought in the current
- * namespace search path.
- */
-Oid
-LookupOperName(List *opername, Oid oprleft, Oid oprright)
-{
- FuncCandidateList clist;
- char oprkind;
-
- if (!OidIsValid(oprleft))
- oprkind = 'l';
- else if (!OidIsValid(oprright))
- oprkind = 'r';
- else
- oprkind = 'b';
-
- clist = OpernameGetCandidates(opername, oprkind);
-
- while (clist)
- {
- if (clist->args[0] == oprleft && clist->args[1] == oprright)
- return clist->oid;
- clist = clist->next;
- }
-
- return InvalidOid;
-}
-
-/*
- * LookupOperNameTypeNames
- * Like LookupOperName, but the argument types are specified by
- * TypeName nodes. Also, if we fail to find the operator
- * and caller is not NULL, then an error is reported.
- *
- * Pass oprleft = NULL for a prefix op, oprright = NULL for a postfix op.
- */
-Oid
-LookupOperNameTypeNames(List *opername, TypeName *oprleft,
- TypeName *oprright, const char *caller)
-{
- Oid operoid;
- Oid leftoid,
- rightoid;
-
- if (oprleft == NULL)
- leftoid = InvalidOid;
- else
- {
- leftoid = LookupTypeName(oprleft);
- if (!OidIsValid(leftoid))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(oprleft));
- }
- if (oprright == NULL)
- rightoid = InvalidOid;
- else
- {
- rightoid = LookupTypeName(oprright);
- if (!OidIsValid(rightoid))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(oprright));
- }
-
- operoid = LookupOperName(opername, leftoid, rightoid);
-
- if (!OidIsValid(operoid) && caller != NULL)
- {
- if (oprleft == NULL)
- elog(ERROR, "%s: Prefix operator '%s' for type '%s' does not exist",
- caller, NameListToString(opername),
- TypeNameToString(oprright));
- else if (oprright == NULL)
- elog(ERROR, "%s: Postfix operator '%s' for type '%s' does not exist",
- caller, NameListToString(opername),
- TypeNameToString(oprleft));
- else
- elog(ERROR, "%s: Operator '%s' for types '%s' and '%s' does not exist",
- caller, NameListToString(opername),
- TypeNameToString(oprleft),
- TypeNameToString(oprright));
- }
-
- return operoid;
-}
-
-
-/* Select an ordering operator for the given datatype */
-Oid
-any_ordering_op(Oid argtype)
-{
- Oid order_opid;
-
- order_opid = compatible_oper_opid(makeList1(makeString("<")),
- argtype, argtype, true);
- if (!OidIsValid(order_opid))
- elog(ERROR, "Unable to identify an ordering operator '%s' for type '%s'"
- "\n\tUse an explicit ordering operator or modify the query",
- "<", format_type_be(argtype));
- return order_opid;
-}
-
-/* given operator tuple, return the operator OID */
-Oid
-oprid(Operator op)
-{
- return op->t_data->t_oid;
-}
-
-/* given operator tuple, return the underlying function's OID */
-Oid
-oprfuncid(Operator op)
-{
- Form_pg_operator pgopform = (Form_pg_operator) GETSTRUCT(op);
-
- return pgopform->oprcode;
-}
-
-
-/* binary_oper_exact()
- * Check for an "exact" match to the specified operand types.
- *
- * If one operand is an unknown literal, assume it should be taken to be
- * the same type as the other operand for this purpose.
- */
-static Oid
-binary_oper_exact(Oid arg1, Oid arg2,
- FuncCandidateList candidates)
-{
- /* Unspecified type for one of the arguments? then use the other */
- if ((arg1 == UNKNOWNOID) && (arg2 != InvalidOid))
- arg1 = arg2;
- else if ((arg2 == UNKNOWNOID) && (arg1 != InvalidOid))
- arg2 = arg1;
-
- while (candidates != NULL)
- {
- if (arg1 == candidates->args[0] &&
- arg2 == candidates->args[1])
- return candidates->oid;
- candidates = candidates->next;
- }
-
- return InvalidOid;
-}
-
-
-/* oper_select_candidate()
- * Given the input argtype array and one or more candidates
- * for the function argtype array, attempt to resolve the conflict.
- * Returns the selected argtype array if the conflict can be resolved,
- * otherwise returns NULL.
- *
- * By design, this is pretty similar to func_select_candidate in parse_func.c.
- * However, we can do a couple of extra things here because we know we can
- * have no more than two args to deal with. Also, the calling convention
- * is a little different: we must prune away "candidates" that aren't actually
- * coercion-compatible with the input types, whereas in parse_func.c that
- * gets done by match_argtypes before func_select_candidate is called.
- *
- * This routine is new code, replacing binary_oper_select_candidate()
- * which dates from v4.2/v1.0.x days. It tries very hard to match up
- * operators with types, including allowing type coercions if necessary.
- * The important thing is that the code do as much as possible,
- * while _never_ doing the wrong thing, where "the wrong thing" would
- * be returning an operator when other better choices are available,
- * or returning an operator which is a non-intuitive possibility.
- * - thomas 1998-05-21
- *
- * The comments below came from binary_oper_select_candidate(), and
- * illustrate the issues and choices which are possible:
- * - thomas 1998-05-20
- *
- * current wisdom holds that the default operator should be one in which
- * both operands have the same type (there will only be one such
- * operator)
- *
- * 7.27.93 - I have decided not to do this; it's too hard to justify, and
- * it's easy enough to typecast explicitly - avi
- * [the rest of this routine was commented out since then - ay]
- *
- * 6/23/95 - I don't complete agree with avi. In particular, casting
- * floats is a pain for users. Whatever the rationale behind not doing
- * this is, I need the following special case to work.
- *
- * In the WHERE clause of a query, if a float is specified without
- * quotes, we treat it as float8. I added the float48* operators so
- * that we can operate on float4 and float8. But now we have more than
- * one matching operator if the right arg is unknown (eg. float
- * specified with quotes). This break some stuff in the regression
- * test where there are floats in quotes not properly casted. Below is
- * the solution. In addition to requiring the operator operates on the
- * same type for both operands [as in the code Avi originally
- * commented out], we also require that the operators be equivalent in
- * some sense. (see equivalentOpersAfterPromotion for details.)
- * - ay 6/95
- */
-static Oid
-oper_select_candidate(int nargs,
- Oid *input_typeids,
- FuncCandidateList candidates)
-{
- FuncCandidateList current_candidate;
- FuncCandidateList last_candidate;
- Oid *current_typeids;
- Oid current_type;
- int unknownOids;
- int i;
- int ncandidates;
- int nbestMatch,
- nmatch;
- CATEGORY slot_category[FUNC_MAX_ARGS],
- current_category;
- bool slot_has_preferred_type[FUNC_MAX_ARGS];
- bool resolved_unknowns;
-
- /*
- * First, delete any candidates that cannot actually accept the given
- * input types, whether directly or by coercion. (Note that
- * can_coerce_type will assume that UNKNOWN inputs are coercible to
- * anything, so candidates will not be eliminated on that basis.)
- */
- ncandidates = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- if (can_coerce_type(nargs, input_typeids, current_candidate->args,
- false))
- {
- if (last_candidate == NULL)
- {
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- else
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- }
- /* otherwise, don't bother keeping this one... */
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- /* Done if no candidate or only one candidate survives */
- if (ncandidates == 0)
- return InvalidOid;
- if (ncandidates == 1)
- return candidates->oid;
-
- /*
- * Run through all candidates and keep those with the most matches on
- * exact types. Keep all candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID &&
- current_typeids[i] == input_typeids[i])
- nmatch++;
- }
-
- /* take this one as the best choice so far? */
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- /* no worse than the last choice, so keep this one too? */
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- /* otherwise, don't bother keeping this one... */
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates->oid;
-
- /*
- * Still too many candidates? Run through all candidates and keep
- * those with the most matches on exact types + binary-compatible
- * types. Keep all candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- {
- if (IsBinaryCompatible(current_typeids[i], input_typeids[i]))
- nmatch++;
- }
- }
-
- /* take this one as the best choice so far? */
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- /* no worse than the last choice, so keep this one too? */
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- /* otherwise, don't bother keeping this one... */
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates->oid;
-
- /*
- * Still too many candidates? Now look for candidates which are
- * preferred types at the args that will require coercion. Keep all
- * candidates if none match.
- */
- ncandidates = 0;
- nbestMatch = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- {
- current_category = TypeCategory(current_typeids[i]);
- if (current_typeids[i] == input_typeids[i] ||
- IsPreferredType(current_category, current_typeids[i]))
- nmatch++;
- }
- }
-
- if ((nmatch > nbestMatch) || (last_candidate == NULL))
- {
- nbestMatch = nmatch;
- candidates = current_candidate;
- last_candidate = current_candidate;
- ncandidates = 1;
- }
- else if (nmatch == nbestMatch)
- {
- last_candidate->next = current_candidate;
- last_candidate = current_candidate;
- ncandidates++;
- }
- }
-
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
-
- if (ncandidates == 1)
- return candidates->oid;
-
- /*
- * Still too many candidates? Try assigning types for the unknown
- * columns.
- *
- * First try: if we have an unknown and a non-unknown input, see whether
- * there is a candidate all of whose input types are the same as the
- * known input type (there can be at most one such candidate). If so,
- * use that candidate. NOTE that this is cool only because operators
- * can't have more than 2 args, so taking the last non-unknown as
- * current_type can yield only one possibility if there is also an
- * unknown.
- */
- unknownOids = FALSE;
- current_type = UNKNOWNOID;
- for (i = 0; i < nargs; i++)
- {
- if ((input_typeids[i] != UNKNOWNOID)
- && (input_typeids[i] != InvalidOid))
- current_type = input_typeids[i];
- else
- unknownOids = TRUE;
- }
-
- if (unknownOids && (current_type != UNKNOWNOID))
- {
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- nmatch = 0;
- for (i = 0; i < nargs; i++)
- {
- if (current_type == current_typeids[i])
- nmatch++;
- }
- if (nmatch == nargs)
- return current_candidate->oid;
- }
- }
-
- /*
- * Second try: same algorithm as for unknown resolution in
- * parse_func.c.
- *
- * We do this by examining each unknown argument position to see if we
- * can determine a "type category" for it. If any candidate has an
- * input datatype of STRING category, use STRING category (this bias
- * towards STRING is appropriate since unknown-type literals look like
- * strings). Otherwise, if all the candidates agree on the type
- * category of this argument position, use that category. Otherwise,
- * fail because we cannot determine a category.
- *
- * If we are able to determine a type category, also notice whether any
- * of the candidates takes a preferred datatype within the category.
- *
- * Having completed this examination, remove candidates that accept the
- * wrong category at any unknown position. Also, if at least one
- * candidate accepted a preferred type at a position, remove
- * candidates that accept non-preferred types.
- *
- * If we are down to one candidate at the end, we win.
- */
- resolved_unknowns = false;
- for (i = 0; i < nargs; i++)
- {
- bool have_conflict;
-
- if (input_typeids[i] != UNKNOWNOID)
- continue;
- resolved_unknowns = true; /* assume we can do it */
- slot_category[i] = INVALID_TYPE;
- slot_has_preferred_type[i] = false;
- have_conflict = false;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- current_typeids = current_candidate->args;
- current_type = current_typeids[i];
- current_category = TypeCategory(current_type);
- if (slot_category[i] == INVALID_TYPE)
- {
- /* first candidate */
- slot_category[i] = current_category;
- slot_has_preferred_type[i] =
- IsPreferredType(current_category, current_type);
- }
- else if (current_category == slot_category[i])
- {
- /* more candidates in same category */
- slot_has_preferred_type[i] |=
- IsPreferredType(current_category, current_type);
- }
- else
- {
- /* category conflict! */
- if (current_category == STRING_TYPE)
- {
- /* STRING always wins if available */
- slot_category[i] = current_category;
- slot_has_preferred_type[i] =
- IsPreferredType(current_category, current_type);
- }
- else
- {
- /*
- * Remember conflict, but keep going (might find
- * STRING)
- */
- have_conflict = true;
- }
- }
- }
- if (have_conflict && slot_category[i] != STRING_TYPE)
- {
- /* Failed to resolve category conflict at this position */
- resolved_unknowns = false;
- break;
- }
- }
-
- if (resolved_unknowns)
- {
- /* Strip non-matching candidates */
- ncandidates = 0;
- last_candidate = NULL;
- for (current_candidate = candidates;
- current_candidate != NULL;
- current_candidate = current_candidate->next)
- {
- bool keepit = true;
-
- current_typeids = current_candidate->args;
- for (i = 0; i < nargs; i++)
- {
- if (input_typeids[i] != UNKNOWNOID)
- continue;
- current_type = current_typeids[i];
- current_category = TypeCategory(current_type);
- if (current_category != slot_category[i])
- {
- keepit = false;
- break;
- }
- if (slot_has_preferred_type[i] &&
- !IsPreferredType(current_category, current_type))
- {
- keepit = false;
- break;
- }
- }
- if (keepit)
- {
- /* keep this candidate */
- last_candidate = current_candidate;
- ncandidates++;
- }
- else
- {
- /* forget this candidate */
- if (last_candidate)
- last_candidate->next = current_candidate->next;
- else
- candidates = current_candidate->next;
- }
- }
- if (last_candidate) /* terminate rebuilt list */
- last_candidate->next = NULL;
- }
-
- if (ncandidates == 1)
- return candidates->oid;
-
- return InvalidOid; /* failed to determine a unique candidate */
-} /* oper_select_candidate() */
-
-
-/* oper() -- search for a binary operator
- * Given operator name, types of arg1 and arg2, return oper struct.
- *
- * IMPORTANT: the returned operator (if any) is only promised to be
- * coercion-compatible with the input datatypes. Do not use this if
- * you need an exact- or binary-compatible match; see compatible_oper.
- *
- * If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
- *
- * NOTE: on success, the returned object is a syscache entry. The caller
- * must ReleaseSysCache() the entry when done with it.
- */
-Operator
-oper(List *opname, Oid ltypeId, Oid rtypeId, bool noError)
-{
- FuncCandidateList clist;
- Oid operOid;
- Oid inputOids[2];
- HeapTuple tup = NULL;
-
- /* Get binary operators of given name */
- clist = OpernameGetCandidates(opname, 'b');
-
- /* No operators found? Then fail... */
- if (clist != NULL)
- {
- /*
- * Check for an "exact" match.
- */
- operOid = binary_oper_exact(ltypeId, rtypeId, clist);
- if (!OidIsValid(operOid))
- {
- /*
- * Otherwise, search for the most suitable candidate.
- */
-
- /* Unspecified type for one of the arguments? then use the other */
- if (rtypeId == InvalidOid)
- rtypeId = ltypeId;
- else if (ltypeId == InvalidOid)
- ltypeId = rtypeId;
- inputOids[0] = ltypeId;
- inputOids[1] = rtypeId;
- operOid = oper_select_candidate(2, inputOids, clist);
- }
- if (OidIsValid(operOid))
- tup = SearchSysCache(OPEROID,
- ObjectIdGetDatum(operOid),
- 0, 0, 0);
- }
-
- if (!HeapTupleIsValid(tup) && !noError)
- op_error(opname, ltypeId, rtypeId);
-
- return (Operator) tup;
-}
-
-/* compatible_oper()
- * given an opname and input datatypes, find a compatible binary operator
- *
- * This is tighter than oper() because it will not return an operator that
- * requires coercion of the input datatypes (but binary-compatible operators
- * are accepted). Otherwise, the semantics are the same.
- */
-Operator
-compatible_oper(List *op, Oid arg1, Oid arg2, bool noError)
-{
- Operator optup;
- Form_pg_operator opform;
-
- /* oper() will find the best available match */
- optup = oper(op, arg1, arg2, noError);
- if (optup == (Operator) NULL)
- return (Operator) NULL; /* must be noError case */
-
- /* but is it good enough? */
- opform = (Form_pg_operator) GETSTRUCT(optup);
- if (IsBinaryCompatible(opform->oprleft, arg1) &&
- IsBinaryCompatible(opform->oprright, arg2))
- return optup;
-
- /* nope... */
- ReleaseSysCache(optup);
-
- if (!noError)
- op_error(op, arg1, arg2);
-
- return (Operator) NULL;
-}
-
-/* compatible_oper_opid() -- get OID of a binary operator
- *
- * This is a convenience routine that extracts only the operator OID
- * from the result of compatible_oper(). InvalidOid is returned if the
- * lookup fails and noError is true.
- */
-Oid
-compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError)
-{
- Operator optup;
- Oid result;
-
- optup = compatible_oper(op, arg1, arg2, noError);
- if (optup != NULL)
- {
- result = oprid(optup);
- ReleaseSysCache(optup);
- return result;
- }
- return InvalidOid;
-}
-
-/* compatible_oper_funcid() -- get OID of a binary operator's function
- *
- * This is a convenience routine that extracts only the function OID
- * from the result of compatible_oper(). InvalidOid is returned if the
- * lookup fails and noError is true.
- */
-Oid
-compatible_oper_funcid(List *op, Oid arg1, Oid arg2, bool noError)
-{
- Operator optup;
- Oid result;
-
- optup = compatible_oper(op, arg1, arg2, noError);
- if (optup != NULL)
- {
- result = oprfuncid(optup);
- ReleaseSysCache(optup);
- return result;
- }
- return InvalidOid;
-}
-
-
-/* right_oper() -- search for a unary right operator (operator on right)
- * Given operator name and type of arg, return oper struct.
- *
- * IMPORTANT: the returned operator (if any) is only promised to be
- * coercion-compatible with the input datatype. Do not use this if
- * you need an exact- or binary-compatible match.
- *
- * If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
- *
- * NOTE: on success, the returned object is a syscache entry. The caller
- * must ReleaseSysCache() the entry when done with it.
- */
-Operator
-right_oper(List *op, Oid arg, bool noError)
-{
- FuncCandidateList clist;
- Oid operOid = InvalidOid;
- HeapTuple tup = NULL;
-
- /* Find candidates */
- clist = OpernameGetCandidates(op, 'r');
-
- if (clist != NULL)
- {
- /*
- * First, quickly check to see if there is an exactly matching
- * operator (there can be only one such entry in the list).
- */
- FuncCandidateList clisti;
-
- for (clisti = clist; clisti != NULL; clisti = clisti->next)
- {
- if (arg == clisti->args[0])
- {
- operOid = clisti->oid;
- break;
- }
- }
-
- if (!OidIsValid(operOid))
- {
- /*
- * We must run oper_select_candidate even if only one
- * candidate, otherwise we may falsely return a
- * non-type-compatible operator.
- */
- operOid = oper_select_candidate(1, &arg, clist);
- }
- if (OidIsValid(operOid))
- tup = SearchSysCache(OPEROID,
- ObjectIdGetDatum(operOid),
- 0, 0, 0);
- }
-
- if (!HeapTupleIsValid(tup) && !noError)
- unary_op_error(op, arg, FALSE);
-
- return (Operator) tup;
-}
-
-
-/* left_oper() -- search for a unary left operator (operator on left)
- * Given operator name and type of arg, return oper struct.
- *
- * IMPORTANT: the returned operator (if any) is only promised to be
- * coercion-compatible with the input datatype. Do not use this if
- * you need an exact- or binary-compatible match.
- *
- * If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
- *
- * NOTE: on success, the returned object is a syscache entry. The caller
- * must ReleaseSysCache() the entry when done with it.
- */
-Operator
-left_oper(List *op, Oid arg, bool noError)
-{
- FuncCandidateList clist;
- Oid operOid = InvalidOid;
- HeapTuple tup = NULL;
-
- /* Find candidates */
- clist = OpernameGetCandidates(op, 'l');
-
- if (clist != NULL)
- {
- /*
- * First, quickly check to see if there is an exactly matching
- * operator (there can be only one such entry in the list).
- *
- * The returned list has args in the form (0, oprright). Move the
- * useful data into args[0] to keep oper_select_candidate simple.
- * XXX we are assuming here that we may scribble on the list!
- */
- FuncCandidateList clisti;
-
- for (clisti = clist; clisti != NULL; clisti = clisti->next)
- {
- clisti->args[0] = clisti->args[1];
- if (arg == clisti->args[0])
- {
- operOid = clisti->oid;
- break;
- }
- }
-
- if (!OidIsValid(operOid))
- {
- /*
- * We must run oper_select_candidate even if only one
- * candidate, otherwise we may falsely return a
- * non-type-compatible operator.
- */
- operOid = oper_select_candidate(1, &arg, clist);
- }
- if (OidIsValid(operOid))
- tup = SearchSysCache(OPEROID,
- ObjectIdGetDatum(operOid),
- 0, 0, 0);
- }
-
- if (!HeapTupleIsValid(tup) && !noError)
- unary_op_error(op, arg, TRUE);
-
- return (Operator) tup;
-}
-
-
-/* op_error()
- * Give a somewhat useful error message when the operator for two types
- * is not found.
- */
-static void
-op_error(List *op, Oid arg1, Oid arg2)
-{
- if (!typeidIsValid(arg1))
- elog(ERROR, "Left hand side of operator '%s' has an unknown type"
- "\n\tProbably a bad attribute name",
- NameListToString(op));
-
- if (!typeidIsValid(arg2))
- elog(ERROR, "Right hand side of operator %s has an unknown type"
- "\n\tProbably a bad attribute name",
- NameListToString(op));
-
- elog(ERROR, "Unable to identify an operator '%s' for types '%s' and '%s'"
- "\n\tYou will have to retype this query using an explicit cast",
- NameListToString(op),
- format_type_be(arg1), format_type_be(arg2));
-}
-
-/* unary_op_error()
- * Give a somewhat useful error message when the operator for one type
- * is not found.
- */
-static void
-unary_op_error(List *op, Oid arg, bool is_left_op)
-{
- if (!typeidIsValid(arg))
- {
- if (is_left_op)
- elog(ERROR, "operand of prefix operator '%s' has an unknown type"
- "\n\t(probably an invalid column reference)",
- NameListToString(op));
- else
- elog(ERROR, "operand of postfix operator '%s' has an unknown type"
- "\n\t(probably an invalid column reference)",
- NameListToString(op));
- }
- else
- {
- if (is_left_op)
- elog(ERROR, "Unable to identify a prefix operator '%s' for type '%s'"
- "\n\tYou may need to add parentheses or an explicit cast",
- NameListToString(op), format_type_be(arg));
- else
- elog(ERROR, "Unable to identify a postfix operator '%s' for type '%s'"
- "\n\tYou may need to add parentheses or an explicit cast",
- NameListToString(op), format_type_be(arg));
- }
-}
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
deleted file mode 100644
index 78a16ea08f8..00000000000
--- a/src/backend/parser/parse_relation.c
+++ /dev/null
@@ -1,1451 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_relation.c
- * parser support routines dealing with relations
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.70 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <ctype.h>
-
-#include "access/heapam.h"
-#include "access/htup.h"
-#include "catalog/heap.h"
-#include "catalog/pg_type.h"
-#include "nodes/makefuncs.h"
-#include "parser/parsetree.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_type.h"
-#include "rewrite/rewriteManip.h"
-#include "utils/builtins.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-
-static Node *scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
- char *refname);
-static Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
- char *colname);
-static bool isForUpdate(ParseState *pstate, char *refname);
-static int specialAttNum(char *a);
-static void warnAutoRange(ParseState *pstate, RangeVar *relation);
-
-
-/*
- * refnameRangeTblEntry
- * Given a refname, look to see if it matches any RTE.
- * If so, return a pointer to the RangeTblEntry.
- * Optionally get its nesting depth (0 = current). If sublevels_up
- * is NULL, only consider items at the current nesting level.
- */
-RangeTblEntry *
-refnameRangeTblEntry(ParseState *pstate,
- char *refname,
- int *sublevels_up)
-{
- if (sublevels_up)
- *sublevels_up = 0;
-
- while (pstate != NULL)
- {
- Node *nsnode;
-
- nsnode = scanNameSpaceForRefname(pstate,
- (Node *) pstate->p_namespace,
- refname);
- if (nsnode)
- {
- /* should get an RTE or JoinExpr */
- if (IsA(nsnode, RangeTblEntry))
- return (RangeTblEntry *) nsnode;
- Assert(IsA(nsnode, JoinExpr));
- return rt_fetch(((JoinExpr *) nsnode)->rtindex, pstate->p_rtable);
- }
-
- pstate = pstate->parentParseState;
- if (sublevels_up)
- (*sublevels_up)++;
- else
- break;
- }
- return NULL;
-}
-
-/*
- * Recursively search a namespace for an RTE or joinexpr with given refname.
- *
- * The top level of p_namespace is a list, and we recurse into any joins
- * that are not subqueries. It is also possible to pass an individual
- * join subtree (useful when checking for name conflicts within a scope).
- *
- * Note: we do not worry about the possibility of multiple matches;
- * we assume the code that built the namespace checked for duplicates.
- */
-static Node *
-scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
- char *refname)
-{
- Node *result = NULL;
-
- if (nsnode == NULL)
- return NULL;
- if (IsA(nsnode, RangeTblRef))
- {
- int varno = ((RangeTblRef *) nsnode)->rtindex;
- RangeTblEntry *rte = rt_fetch(varno, pstate->p_rtable);
-
- if (strcmp(rte->eref->aliasname, refname) == 0)
- result = (Node *) rte;
- }
- else if (IsA(nsnode, JoinExpr))
- {
- JoinExpr *j = (JoinExpr *) nsnode;
-
- if (j->alias)
- {
- if (strcmp(j->alias->aliasname, refname) == 0)
- return (Node *) j; /* matched a join alias */
-
- /*
- * Tables within an aliased join are invisible from outside
- * the join, according to the scope rules of SQL92 (the join
- * is considered a subquery). So, stop here.
- */
- return NULL;
- }
- result = scanNameSpaceForRefname(pstate, j->larg, refname);
- if (!result)
- result = scanNameSpaceForRefname(pstate, j->rarg, refname);
- }
- else if (IsA(nsnode, List))
- {
- List *l;
-
- foreach(l, (List *) nsnode)
- {
- result = scanNameSpaceForRefname(pstate, lfirst(l), refname);
- if (result)
- break;
- }
- }
- else
- elog(ERROR, "scanNameSpaceForRefname: unexpected node type %d",
- nodeTag(nsnode));
- return result;
-}
-
-/* Convenience subroutine for checkNameSpaceConflicts */
-static void
-scanNameSpaceForConflict(ParseState *pstate, Node *nsnode,
- char *refname)
-{
- if (scanNameSpaceForRefname(pstate, nsnode, refname) != NULL)
- elog(ERROR, "Table name \"%s\" specified more than once", refname);
-}
-
-/*
- * Recursively check for refname conflicts between two namespaces or
- * namespace subtrees. Raise an error if any is found.
- *
- * Works by recursively scanning namespace1 in the same way that
- * scanNameSpaceForRefname does, and then looking in namespace2 for
- * a match to each refname found in namespace1.
- *
- * Note: we assume that each given argument does not contain conflicts
- * itself; we just want to know if the two can be merged together.
- */
-void
-checkNameSpaceConflicts(ParseState *pstate, Node *namespace1,
- Node *namespace2)
-{
- if (namespace1 == NULL)
- return;
- if (IsA(namespace1, RangeTblRef))
- {
- int varno = ((RangeTblRef *) namespace1)->rtindex;
- RangeTblEntry *rte = rt_fetch(varno, pstate->p_rtable);
-
- scanNameSpaceForConflict(pstate, namespace2, rte->eref->aliasname);
- }
- else if (IsA(namespace1, JoinExpr))
- {
- JoinExpr *j = (JoinExpr *) namespace1;
-
- if (j->alias)
- {
- scanNameSpaceForConflict(pstate, namespace2, j->alias->aliasname);
-
- /*
- * Tables within an aliased join are invisible from outside
- * the join, according to the scope rules of SQL92 (the join
- * is considered a subquery). So, stop here.
- */
- return;
- }
- checkNameSpaceConflicts(pstate, j->larg, namespace2);
- checkNameSpaceConflicts(pstate, j->rarg, namespace2);
- }
- else if (IsA(namespace1, List))
- {
- List *l;
-
- foreach(l, (List *) namespace1)
- checkNameSpaceConflicts(pstate, lfirst(l), namespace2);
- }
- else
- elog(ERROR, "checkNameSpaceConflicts: unexpected node type %d",
- nodeTag(namespace1));
-}
-
-/*
- * given an RTE, return RT index (starting with 1) of the entry,
- * and optionally get its nesting depth (0 = current). If sublevels_up
- * is NULL, only consider rels at the current nesting level.
- * Raises error if RTE not found.
- */
-int
-RTERangeTablePosn(ParseState *pstate, RangeTblEntry *rte, int *sublevels_up)
-{
- int index;
- List *temp;
-
- if (sublevels_up)
- *sublevels_up = 0;
-
- while (pstate != NULL)
- {
- index = 1;
- foreach(temp, pstate->p_rtable)
- {
- if (rte == (RangeTblEntry *) lfirst(temp))
- return index;
- index++;
- }
- pstate = pstate->parentParseState;
- if (sublevels_up)
- (*sublevels_up)++;
- else
- break;
- }
-
- elog(ERROR, "RTERangeTablePosn: RTE not found (internal error)");
- return 0; /* keep compiler quiet */
-}
-
-/*
- * scanRTEForColumn
- * Search the column names of a single RTE for the given name.
- * If found, return an appropriate Var node, else return NULL.
- * If the name proves ambiguous within this RTE, raise error.
- *
- * Side effect: if we find a match, mark the RTE as requiring read access.
- * See comments in setTargetTable().
- *
- * NOTE: if the RTE is for a join, marking it as requiring read access does
- * nothing. It might seem that we need to propagate the mark to all the
- * contained RTEs, but that is not necessary. This is so because a join
- * expression can only appear in a FROM clause, and any table named in
- * FROM will be marked checkForRead from the beginning.
- */
-static Node *
-scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname)
-{
- Node *result = NULL;
- int attnum = 0;
- List *c;
-
- /*
- * Scan the user column names (or aliases) for a match. Complain if
- * multiple matches.
- */
- foreach(c, rte->eref->colnames)
- {
- attnum++;
- if (strcmp(strVal(lfirst(c)), colname) == 0)
- {
- if (result)
- elog(ERROR, "Column reference \"%s\" is ambiguous", colname);
- result = (Node *) make_var(pstate, rte, attnum);
- rte->checkForRead = true;
- }
- }
-
- /*
- * If we have a unique match, return it. Note that this allows a user
- * alias to override a system column name (such as OID) without error.
- */
- if (result)
- return result;
-
- /*
- * If the RTE represents a real table, consider system column names.
- */
- if (rte->rtekind == RTE_RELATION)
- {
- /* quick check to see if name could be a system column */
- attnum = specialAttNum(colname);
- if (attnum != InvalidAttrNumber)
- {
- /* now check to see if column actually is defined */
- if (SearchSysCacheExists(ATTNUM,
- ObjectIdGetDatum(rte->relid),
- Int16GetDatum(attnum),
- 0, 0))
- {
- result = (Node *) make_var(pstate, rte, attnum);
- rte->checkForRead = true;
- }
- }
- }
-
- return result;
-}
-
-/*
- * colnameToVar
- * Search for an unqualified column name.
- * If found, return the appropriate Var node (or expression).
- * If not found, return NULL. If the name proves ambiguous, raise error.
- */
-Node *
-colnameToVar(ParseState *pstate, char *colname)
-{
- Node *result = NULL;
- ParseState *orig_pstate = pstate;
- int levels_up = 0;
-
- while (pstate != NULL)
- {
- List *ns;
-
- /*
- * We need to look only at top-level namespace items, and even for
- * those, ignore RTEs that are marked as not inFromCl and not the
- * query's target relation.
- */
- foreach(ns, pstate->p_namespace)
- {
- Node *nsnode = (Node *) lfirst(ns);
- Node *newresult = NULL;
-
- if (IsA(nsnode, RangeTblRef))
- {
- int varno = ((RangeTblRef *) nsnode)->rtindex;
- RangeTblEntry *rte = rt_fetch(varno, pstate->p_rtable);
-
- if (!rte->inFromCl &&
- rte != pstate->p_target_rangetblentry)
- continue;
-
- /* use orig_pstate here to get the right sublevels_up */
- newresult = scanRTEForColumn(orig_pstate, rte, colname);
- }
- else if (IsA(nsnode, JoinExpr))
- {
- int varno = ((JoinExpr *) nsnode)->rtindex;
- RangeTblEntry *rte = rt_fetch(varno, pstate->p_rtable);
-
- /* joins are always inFromCl, so no need to check */
-
- /* use orig_pstate here to get the right sublevels_up */
- newresult = scanRTEForColumn(orig_pstate, rte, colname);
- }
- else
- elog(ERROR, "colnameToVar: unexpected node type %d",
- nodeTag(nsnode));
-
- if (newresult)
- {
- if (result)
- elog(ERROR, "Column reference \"%s\" is ambiguous",
- colname);
- result = newresult;
- }
- }
-
- if (result != NULL)
- break; /* found */
-
- pstate = pstate->parentParseState;
- levels_up++;
- }
-
- return result;
-}
-
-/*
- * qualifiedNameToVar
- * Search for a qualified column name (refname + column name).
- * If found, return the appropriate Var node.
- * If not found, return NULL. If the name proves ambiguous, raise error.
- */
-Node *
-qualifiedNameToVar(ParseState *pstate, char *refname, char *colname,
- bool implicitRTEOK)
-{
- RangeTblEntry *rte;
- int sublevels_up;
-
- rte = refnameRangeTblEntry(pstate, refname, &sublevels_up);
-
- if (rte == NULL)
- {
- if (!implicitRTEOK)
- return NULL;
- rte = addImplicitRTE(pstate, makeRangeVar(NULL, refname));
- }
-
- return scanRTEForColumn(pstate, rte, colname);
-}
-
-/*
- * Add an entry for a relation to the pstate's range table (p_rtable).
- *
- * If pstate is NULL, we just build an RTE and return it without adding it
- * to an rtable list.
- *
- * Note: formerly this checked for refname conflicts, but that's wrong.
- * Caller is responsible for checking for conflicts in the appropriate scope.
- */
-RangeTblEntry *
-addRangeTableEntry(ParseState *pstate,
- RangeVar *relation,
- Alias *alias,
- bool inh,
- bool inFromCl)
-{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
- char *refname = alias ? alias->aliasname : relation->relname;
- LOCKMODE lockmode;
- Relation rel;
- Alias *eref;
- int maxattrs;
- int numaliases;
- int varattno;
-
- rte->rtekind = RTE_RELATION;
- rte->alias = alias;
-
- /*
- * Get the rel's OID. This access also ensures that we have an
- * up-to-date relcache entry for the rel. Since this is typically the
- * first access to a rel in a statement, be careful to get the right
- * access level depending on whether we're doing SELECT FOR UPDATE.
- */
- lockmode = isForUpdate(pstate, refname) ? RowShareLock : AccessShareLock;
- rel = heap_openrv(relation, lockmode);
- rte->relid = RelationGetRelid(rel);
-
- eref = alias ? (Alias *) copyObject(alias) : makeAlias(refname, NIL);
- numaliases = length(eref->colnames);
-
- /*
- * Since the rel is open anyway, let's check that the number of column
- * aliases is reasonable. - Thomas 2000-02-04
- */
- maxattrs = RelationGetNumberOfAttributes(rel);
- if (maxattrs < numaliases)
- elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
- RelationGetRelationName(rel), maxattrs, numaliases);
-
- /* fill in any unspecified alias columns using actual column names */
- for (varattno = numaliases; varattno < maxattrs; varattno++)
- {
- char *attrname;
-
- attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname));
- eref->colnames = lappend(eref->colnames, makeString(attrname));
- }
- rte->eref = eref;
-
- /*
- * Drop the rel refcount, but keep the access lock till end of
- * transaction so that the table can't be deleted or have its schema
- * modified underneath us.
- */
- heap_close(rel, NoLock);
-
- /*----------
- * Flags:
- * - this RTE should be expanded to include descendant tables,
- * - this RTE is in the FROM clause,
- * - this RTE should be checked for read/write access rights.
- *
- * The initial default on access checks is always check-for-READ-access,
- * which is the right thing for all except target tables.
- *----------
- */
- rte->inh = inh;
- rte->inFromCl = inFromCl;
- rte->checkForRead = true;
- rte->checkForWrite = false;
-
- rte->checkAsUser = InvalidOid; /* not set-uid by default, either */
-
- /*
- * Add completed RTE to pstate's range table list, but not to join
- * list nor namespace --- caller must do that if appropriate.
- */
- if (pstate != NULL)
- pstate->p_rtable = lappend(pstate->p_rtable, rte);
-
- return rte;
-}
-
-/*
- * Add an entry for a relation to the pstate's range table (p_rtable).
- *
- * This is just like addRangeTableEntry() except that it makes an RTE
- * given a relation OID instead of a RangeVar reference.
- *
- * Note that an alias clause *must* be supplied.
- */
-RangeTblEntry *
-addRangeTableEntryForRelation(ParseState *pstate,
- Oid relid,
- Alias *alias,
- bool inh,
- bool inFromCl)
-{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
- char *refname = alias->aliasname;
- LOCKMODE lockmode;
- Relation rel;
- Alias *eref;
- int maxattrs;
- int numaliases;
- int varattno;
-
- rte->rtekind = RTE_RELATION;
- rte->alias = alias;
-
- /*
- * Get the rel's relcache entry. This access ensures that we have an
- * up-to-date relcache entry for the rel. Since this is typically the
- * first access to a rel in a statement, be careful to get the right
- * access level depending on whether we're doing SELECT FOR UPDATE.
- */
- lockmode = isForUpdate(pstate, refname) ? RowShareLock : AccessShareLock;
- rel = heap_open(relid, lockmode);
- rte->relid = relid;
-
- eref = (Alias *) copyObject(alias);
- numaliases = length(eref->colnames);
-
- /*
- * Since the rel is open anyway, let's check that the number of column
- * aliases is reasonable. - Thomas 2000-02-04
- */
- maxattrs = RelationGetNumberOfAttributes(rel);
- if (maxattrs < numaliases)
- elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
- RelationGetRelationName(rel), maxattrs, numaliases);
-
- /* fill in any unspecified alias columns using actual column names */
- for (varattno = numaliases; varattno < maxattrs; varattno++)
- {
- char *attrname;
-
- attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname));
- eref->colnames = lappend(eref->colnames, makeString(attrname));
- }
- rte->eref = eref;
-
- /*
- * Drop the rel refcount, but keep the access lock till end of
- * transaction so that the table can't be deleted or have its schema
- * modified underneath us.
- */
- heap_close(rel, NoLock);
-
- /*----------
- * Flags:
- * - this RTE should be expanded to include descendant tables,
- * - this RTE is in the FROM clause,
- * - this RTE should be checked for read/write access rights.
- *
- * The initial default on access checks is always check-for-READ-access,
- * which is the right thing for all except target tables.
- *----------
- */
- rte->inh = inh;
- rte->inFromCl = inFromCl;
- rte->checkForRead = true;
- rte->checkForWrite = false;
-
- rte->checkAsUser = InvalidOid; /* not set-uid by default, either */
-
- /*
- * Add completed RTE to pstate's range table list, but not to join
- * list nor namespace --- caller must do that if appropriate.
- */
- if (pstate != NULL)
- pstate->p_rtable = lappend(pstate->p_rtable, rte);
-
- return rte;
-}
-
-/*
- * Add an entry for a subquery to the pstate's range table (p_rtable).
- *
- * This is just like addRangeTableEntry() except that it makes a subquery RTE.
- * Note that an alias clause *must* be supplied.
- */
-RangeTblEntry *
-addRangeTableEntryForSubquery(ParseState *pstate,
- Query *subquery,
- Alias *alias,
- bool inFromCl)
-{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
- char *refname = alias->aliasname;
- Alias *eref;
- int numaliases;
- int varattno;
- List *tlistitem;
-
- rte->rtekind = RTE_SUBQUERY;
- rte->relid = InvalidOid;
- rte->subquery = subquery;
- rte->alias = alias;
-
- eref = copyObject(alias);
- numaliases = length(eref->colnames);
-
- /* fill in any unspecified alias columns */
- varattno = 0;
- foreach(tlistitem, subquery->targetList)
- {
- TargetEntry *te = (TargetEntry *) lfirst(tlistitem);
-
- if (te->resdom->resjunk)
- continue;
- varattno++;
- Assert(varattno == te->resdom->resno);
- if (varattno > numaliases)
- {
- char *attrname;
-
- attrname = pstrdup(te->resdom->resname);
- eref->colnames = lappend(eref->colnames, makeString(attrname));
- }
- }
- if (varattno < numaliases)
- elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
- refname, varattno, numaliases);
-
- rte->eref = eref;
-
- /*----------
- * Flags:
- * - this RTE should be expanded to include descendant tables,
- * - this RTE is in the FROM clause,
- * - this RTE should be checked for read/write access rights.
- *
- * Subqueries are never checked for access rights.
- *----------
- */
- rte->inh = false; /* never true for subqueries */
- rte->inFromCl = inFromCl;
- rte->checkForRead = false;
- rte->checkForWrite = false;
-
- rte->checkAsUser = InvalidOid;
-
- /*
- * Add completed RTE to pstate's range table list, but not to join
- * list nor namespace --- caller must do that if appropriate.
- */
- if (pstate != NULL)
- pstate->p_rtable = lappend(pstate->p_rtable, rte);
-
- return rte;
-}
-
-/*
- * Add an entry for a function to the pstate's range table (p_rtable).
- *
- * This is just like addRangeTableEntry() except that it makes a function RTE.
- */
-RangeTblEntry *
-addRangeTableEntryForFunction(ParseState *pstate,
- char *funcname,
- Node *funcexpr,
- Alias *alias,
- bool inFromCl)
-{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
- Oid funcrettype = exprType(funcexpr);
- Oid funcrelid;
- Alias *eref;
- int numaliases;
- int varattno;
-
- rte->rtekind = RTE_FUNCTION;
- rte->relid = InvalidOid;
- rte->subquery = NULL;
- rte->funcexpr = funcexpr;
- rte->alias = alias;
-
- eref = alias ? (Alias *) copyObject(alias) : makeAlias(funcname, NIL);
- rte->eref = eref;
-
- numaliases = length(eref->colnames);
-
- /*
- * Now determine if the function returns a simple or composite type,
- * and check/add column aliases.
- */
- funcrelid = typeidTypeRelid(funcrettype);
-
- if (OidIsValid(funcrelid))
- {
- /*
- * Composite data type, i.e. a table's row type
- *
- * Get the rel's relcache entry. This access ensures that we have an
- * up-to-date relcache entry for the rel.
- */
- Relation rel;
- int maxattrs;
-
- rel = heap_open(funcrelid, AccessShareLock);
-
- /*
- * Since the rel is open anyway, let's check that the number of column
- * aliases is reasonable.
- */
- maxattrs = RelationGetNumberOfAttributes(rel);
- if (maxattrs < numaliases)
- elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
- RelationGetRelationName(rel), maxattrs, numaliases);
-
- /* fill in alias columns using actual column names */
- for (varattno = numaliases; varattno < maxattrs; varattno++)
- {
- char *attrname;
-
- attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname));
- eref->colnames = lappend(eref->colnames, makeString(attrname));
- }
-
- /*
- * Drop the rel refcount, but keep the access lock till end of
- * transaction so that the table can't be deleted or have its schema
- * modified underneath us.
- */
- heap_close(rel, NoLock);
- }
- else
- {
- /*
- * Must be a base data type, i.e. scalar.
- * Just add one alias column named for the function.
- */
- if (numaliases > 1)
- elog(ERROR, "Too many column aliases specified for function %s",
- funcname);
- if (numaliases == 0)
- eref->colnames = makeList1(makeString(funcname));
- }
-
- /*----------
- * Flags:
- * - this RTE should be expanded to include descendant tables,
- * - this RTE is in the FROM clause,
- * - this RTE should be checked for read/write access rights.
- *----------
- */
- rte->inh = false; /* never true for functions */
- rte->inFromCl = inFromCl;
- rte->checkForRead = true;
- rte->checkForWrite = false;
-
- rte->checkAsUser = InvalidOid;
-
- /*
- * Add completed RTE to pstate's range table list, but not to join
- * list nor namespace --- caller must do that if appropriate.
- */
- if (pstate != NULL)
- pstate->p_rtable = lappend(pstate->p_rtable, rte);
-
- return rte;
-}
-
-/*
- * Add an entry for a join to the pstate's range table (p_rtable).
- *
- * This is much like addRangeTableEntry() except that it makes a join RTE.
- */
-RangeTblEntry *
-addRangeTableEntryForJoin(ParseState *pstate,
- List *colnames,
- JoinType jointype,
- List *aliasvars,
- Alias *alias,
- bool inFromCl)
-{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
- Alias *eref;
- int numaliases;
-
- rte->rtekind = RTE_JOIN;
- rte->relid = InvalidOid;
- rte->subquery = NULL;
- rte->jointype = jointype;
- rte->joinaliasvars = aliasvars;
- rte->alias = alias;
-
- eref = alias ? (Alias *) copyObject(alias) : makeAlias("unnamed_join", NIL);
- numaliases = length(eref->colnames);
-
- /* fill in any unspecified alias columns */
- if (numaliases < length(colnames))
- {
- while (numaliases-- > 0)
- colnames = lnext(colnames);
- eref->colnames = nconc(eref->colnames, colnames);
- }
-
- rte->eref = eref;
-
- /*----------
- * Flags:
- * - this RTE should be expanded to include descendant tables,
- * - this RTE is in the FROM clause,
- * - this RTE should be checked for read/write access rights.
- *
- * Joins are never checked for access rights.
- *----------
- */
- rte->inh = false; /* never true for joins */
- rte->inFromCl = inFromCl;
- rte->checkForRead = false;
- rte->checkForWrite = false;
-
- rte->checkAsUser = InvalidOid;
-
- /*
- * Add completed RTE to pstate's range table list, but not to join
- * list nor namespace --- caller must do that if appropriate.
- */
- if (pstate != NULL)
- pstate->p_rtable = lappend(pstate->p_rtable, rte);
-
- return rte;
-}
-
-/*
- * Has the specified refname been selected FOR UPDATE?
- */
-static bool
-isForUpdate(ParseState *pstate, char *refname)
-{
- /* Outer loop to check parent query levels as well as this one */
- while (pstate != NULL)
- {
- if (pstate->p_forUpdate != NIL)
- {
- if (lfirst(pstate->p_forUpdate) == NULL)
- {
- /* all tables used in query */
- return true;
- }
- else
- {
- /* just the named tables */
- List *l;
-
- foreach(l, pstate->p_forUpdate)
- {
- char *rname = strVal(lfirst(l));
-
- if (strcmp(refname, rname) == 0)
- return true;
- }
- }
- }
- pstate = pstate->parentParseState;
- }
- return false;
-}
-
-/*
- * Add the given RTE as a top-level entry in the pstate's join list
- * and/or name space list. (We assume caller has checked for any
- * namespace conflict.)
- */
-void
-addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
- bool addToJoinList, bool addToNameSpace)
-{
- int rtindex = RTERangeTablePosn(pstate, rte, NULL);
- RangeTblRef *rtr = makeNode(RangeTblRef);
-
- rtr->rtindex = rtindex;
-
- if (addToJoinList)
- pstate->p_joinlist = lappend(pstate->p_joinlist, rtr);
- if (addToNameSpace)
- pstate->p_namespace = lappend(pstate->p_namespace, rtr);
-}
-
-/*
- * Add a POSTQUEL-style implicit RTE.
- *
- * We assume caller has already checked that there is no RTE or join with
- * a conflicting name.
- */
-RangeTblEntry *
-addImplicitRTE(ParseState *pstate, RangeVar *relation)
-{
- RangeTblEntry *rte;
-
- rte = addRangeTableEntry(pstate, relation, NULL, false, false);
- addRTEtoQuery(pstate, rte, true, true);
- warnAutoRange(pstate, relation);
-
- return rte;
-}
-
-/* expandRTE()
- *
- * Given a rangetable entry, create lists of its column names (aliases if
- * provided, else real names) and Vars for each column. Only user columns
- * are considered, since this is primarily used to expand '*' and determine
- * the contents of JOIN tables.
- *
- * If only one of the two kinds of output list is needed, pass NULL for the
- * output pointer for the unwanted one.
- */
-void
-expandRTE(ParseState *pstate, RangeTblEntry *rte,
- List **colnames, List **colvars)
-{
- int rtindex,
- sublevels_up,
- varattno;
-
- if (colnames)
- *colnames = NIL;
- if (colvars)
- *colvars = NIL;
-
- /* Need the RT index of the entry for creating Vars */
- rtindex = RTERangeTablePosn(pstate, rte, &sublevels_up);
-
- switch (rte->rtekind)
- {
- case RTE_RELATION:
- {
- /* Ordinary relation RTE */
- Relation rel;
- int maxattrs;
- int numaliases;
-
- rel = heap_open(rte->relid, AccessShareLock);
- maxattrs = RelationGetNumberOfAttributes(rel);
- numaliases = length(rte->eref->colnames);
-
- for (varattno = 0; varattno < maxattrs; varattno++)
- {
- Form_pg_attribute attr = rel->rd_att->attrs[varattno];
-
- if (colnames)
- {
- char *label;
-
- if (varattno < numaliases)
- label = strVal(nth(varattno, rte->eref->colnames));
- else
- label = NameStr(attr->attname);
- *colnames = lappend(*colnames, makeString(pstrdup(label)));
- }
-
- if (colvars)
- {
- Var *varnode;
-
- varnode = makeVar(rtindex, attr->attnum,
- attr->atttypid, attr->atttypmod,
- sublevels_up);
-
- *colvars = lappend(*colvars, varnode);
- }
- }
-
- heap_close(rel, AccessShareLock);
- }
- break;
- case RTE_SUBQUERY:
- {
- /* Subquery RTE */
- List *aliasp = rte->eref->colnames;
- List *tlistitem;
-
- varattno = 0;
- foreach(tlistitem, rte->subquery->targetList)
- {
- TargetEntry *te = (TargetEntry *) lfirst(tlistitem);
-
- if (te->resdom->resjunk)
- continue;
- varattno++;
- Assert(varattno == te->resdom->resno);
-
- if (colnames)
- {
- /* Assume there is one alias per target item */
- char *label = strVal(lfirst(aliasp));
-
- *colnames = lappend(*colnames, makeString(pstrdup(label)));
- aliasp = lnext(aliasp);
- }
-
- if (colvars)
- {
- Var *varnode;
-
- varnode = makeVar(rtindex, varattno,
- te->resdom->restype,
- te->resdom->restypmod,
- sublevels_up);
-
- *colvars = lappend(*colvars, varnode);
- }
- }
- }
- break;
- case RTE_FUNCTION:
- {
- /* Function RTE */
- Oid funcrettype = exprType(rte->funcexpr);
- Oid funcrelid = typeidTypeRelid(funcrettype);
-
- if (OidIsValid(funcrelid))
- {
- /*
- * Composite data type, i.e. a table's row type
- * Same as ordinary relation RTE
- */
- Relation rel;
- int maxattrs;
- int numaliases;
-
- rel = heap_open(funcrelid, AccessShareLock);
- maxattrs = RelationGetNumberOfAttributes(rel);
- numaliases = length(rte->eref->colnames);
-
- for (varattno = 0; varattno < maxattrs; varattno++)
- {
- Form_pg_attribute attr = rel->rd_att->attrs[varattno];
-
- if (colnames)
- {
- char *label;
-
- if (varattno < numaliases)
- label = strVal(nth(varattno, rte->eref->colnames));
- else
- label = NameStr(attr->attname);
- *colnames = lappend(*colnames, makeString(pstrdup(label)));
- }
-
- if (colvars)
- {
- Var *varnode;
-
- varnode = makeVar(rtindex, attr->attnum,
- attr->atttypid, attr->atttypmod,
- sublevels_up);
-
- *colvars = lappend(*colvars, varnode);
- }
- }
-
- heap_close(rel, AccessShareLock);
- }
- else
- {
- /*
- * Must be a base data type, i.e. scalar
- */
- if (colnames)
- *colnames = lappend(*colnames,
- lfirst(rte->eref->colnames));
-
- if (colvars)
- {
- Var *varnode;
-
- varnode = makeVar(rtindex, 1,
- funcrettype, -1,
- sublevels_up);
-
- *colvars = lappend(*colvars, varnode);
- }
- }
- }
- break;
- case RTE_JOIN:
- {
- /* Join RTE */
- List *aliasp = rte->eref->colnames;
- List *aliasvars = rte->joinaliasvars;
-
- varattno = 0;
- while (aliasp)
- {
- Assert(aliasvars);
- varattno++;
-
- if (colnames)
- {
- char *label = strVal(lfirst(aliasp));
-
- *colnames = lappend(*colnames, makeString(pstrdup(label)));
- }
-
- if (colvars)
- {
- Node *aliasvar = (Node *) lfirst(aliasvars);
- Var *varnode;
-
- varnode = makeVar(rtindex, varattno,
- exprType(aliasvar),
- exprTypmod(aliasvar),
- sublevels_up);
-
- *colvars = lappend(*colvars, varnode);
- }
-
- aliasp = lnext(aliasp);
- aliasvars = lnext(aliasvars);
- }
- Assert(aliasvars == NIL);
- }
- break;
- default:
- elog(ERROR, "expandRTE: unsupported RTE kind %d",
- (int) rte->rtekind);
- }
-}
-
-/*
- * expandRelAttrs -
- * Workhorse for "*" expansion: produce a list of targetentries
- * for the attributes of the rte
- */
-List *
-expandRelAttrs(ParseState *pstate, RangeTblEntry *rte)
-{
- List *names,
- *vars;
- List *te_list = NIL;
-
- expandRTE(pstate, rte, &names, &vars);
-
- while (names)
- {
- char *label = strVal(lfirst(names));
- Node *varnode = (Node *) lfirst(vars);
- TargetEntry *te = makeNode(TargetEntry);
-
- te->resdom = makeResdom((AttrNumber) (pstate->p_last_resno)++,
- exprType(varnode),
- exprTypmod(varnode),
- label,
- false);
- te->expr = varnode;
- te_list = lappend(te_list, te);
-
- names = lnext(names);
- vars = lnext(vars);
- }
-
- Assert(vars == NIL); /* lists not same length? */
-
- return te_list;
-}
-
-/*
- * get_rte_attribute_name
- * Get an attribute name from a RangeTblEntry
- *
- * This is unlike get_attname() because we use aliases if available.
- * In particular, it will work on an RTE for a subselect or join, whereas
- * get_attname() only works on real relations.
- *
- * "*" is returned if the given attnum is InvalidAttrNumber --- this case
- * occurs when a Var represents a whole tuple of a relation.
- */
-char *
-get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
-{
- char *attname;
-
- if (attnum == InvalidAttrNumber)
- return "*";
-
- /*
- * If there is an alias, use it. (This path should always be taken
- * for non-relation RTEs.)
- */
- if (attnum > 0 && attnum <= length(rte->eref->colnames))
- return strVal(nth(attnum - 1, rte->eref->colnames));
-
- /*
- * Can get here for a system attribute (which never has an alias), or
- * if alias name list is too short (which probably can't happen
- * anymore). Neither of these cases is valid for a non-relation RTE.
- */
- if (rte->rtekind != RTE_RELATION)
- elog(ERROR, "Invalid attnum %d for rangetable entry %s",
- attnum, rte->eref->aliasname);
-
- /*
- * Use the real name of the table's column
- */
- attname = get_attname(rte->relid, attnum);
- if (attname == NULL)
- elog(ERROR, "cache lookup of attribute %d in relation %u failed",
- attnum, rte->relid);
- return attname;
-}
-
-/*
- * get_rte_attribute_type
- * Get attribute type information from a RangeTblEntry
- */
-void
-get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
- Oid *vartype, int32 *vartypmod)
-{
- switch (rte->rtekind)
- {
- case RTE_RELATION:
- {
- /* Plain relation RTE --- get the attribute's type info */
- HeapTuple tp;
- Form_pg_attribute att_tup;
-
- tp = SearchSysCache(ATTNUM,
- ObjectIdGetDatum(rte->relid),
- Int16GetDatum(attnum),
- 0, 0);
- /* this shouldn't happen... */
- if (!HeapTupleIsValid(tp))
- elog(ERROR, "Relation %s does not have attribute %d",
- get_rel_name(rte->relid), attnum);
- att_tup = (Form_pg_attribute) GETSTRUCT(tp);
- *vartype = att_tup->atttypid;
- *vartypmod = att_tup->atttypmod;
- ReleaseSysCache(tp);
- }
- break;
- case RTE_SUBQUERY:
- {
- /* Subselect RTE --- get type info from subselect's tlist */
- List *tlistitem;
-
- foreach(tlistitem, rte->subquery->targetList)
- {
- TargetEntry *te = (TargetEntry *) lfirst(tlistitem);
-
- if (te->resdom->resjunk || te->resdom->resno != attnum)
- continue;
- *vartype = te->resdom->restype;
- *vartypmod = te->resdom->restypmod;
- return;
- }
- /* falling off end of list shouldn't happen... */
- elog(ERROR, "Subquery %s does not have attribute %d",
- rte->eref->aliasname, attnum);
- }
- break;
- case RTE_FUNCTION:
- {
- /* Function RTE */
- Oid funcrettype = exprType(rte->funcexpr);
- Oid funcrelid = typeidTypeRelid(funcrettype);
-
- if (OidIsValid(funcrelid))
- {
- /*
- * Composite data type, i.e. a table's row type
- * Same as ordinary relation RTE
- */
- HeapTuple tp;
- Form_pg_attribute att_tup;
-
- tp = SearchSysCache(ATTNUM,
- ObjectIdGetDatum(funcrelid),
- Int16GetDatum(attnum),
- 0, 0);
- /* this shouldn't happen... */
- if (!HeapTupleIsValid(tp))
- elog(ERROR, "Relation %s does not have attribute %d",
- get_rel_name(funcrelid), attnum);
- att_tup = (Form_pg_attribute) GETSTRUCT(tp);
- *vartype = att_tup->atttypid;
- *vartypmod = att_tup->atttypmod;
- ReleaseSysCache(tp);
- }
- else
- {
- /*
- * Must be a base data type, i.e. scalar
- */
- *vartype = funcrettype;
- *vartypmod = -1;
- }
- }
- break;
- case RTE_JOIN:
- {
- /* Join RTE --- get type info from join RTE's alias variable */
- Node *aliasvar;
-
- Assert(attnum > 0 && attnum <= length(rte->joinaliasvars));
- aliasvar = (Node *) nth(attnum-1, rte->joinaliasvars);
- *vartype = exprType(aliasvar);
- *vartypmod = exprTypmod(aliasvar);
- }
- break;
- default:
- elog(ERROR, "get_rte_attribute_type: unsupported RTE kind %d",
- (int) rte->rtekind);
- }
-}
-
-/*
- * given relation and att name, return id of variable
- *
- * This should only be used if the relation is already
- * heap_open()'ed. Use the cache version get_attnum()
- * for access to non-opened relations.
- */
-int
-attnameAttNum(Relation rd, char *a)
-{
- int i;
-
- for (i = 0; i < rd->rd_rel->relnatts; i++)
- if (namestrcmp(&(rd->rd_att->attrs[i]->attname), a) == 0)
- return i + 1;
-
- if ((i = specialAttNum(a)) != InvalidAttrNumber)
- {
- if (i != ObjectIdAttributeNumber || rd->rd_rel->relhasoids)
- return i;
- }
-
- /* on failure */
- elog(ERROR, "Relation '%s' does not have attribute '%s'",
- RelationGetRelationName(rd), a);
- return InvalidAttrNumber; /* lint */
-}
-
-/* specialAttNum()
- *
- * Check attribute name to see if it is "special", e.g. "oid".
- * - thomas 2000-02-07
- *
- * Note: this only discovers whether the name could be a system attribute.
- * Caller needs to verify that it really is an attribute of the rel,
- * at least in the case of "oid", which is now optional.
- */
-static int
-specialAttNum(char *a)
-{
- Form_pg_attribute sysatt;
-
- sysatt = SystemAttributeByName(a, true /* "oid" will be accepted */ );
- if (sysatt != NULL)
- return sysatt->attnum;
- return InvalidAttrNumber;
-}
-
-
-/*
- * given attribute id, return name of that attribute
- *
- * This should only be used if the relation is already
- * heap_open()'ed. Use the cache version get_atttype()
- * for access to non-opened relations.
- */
-Name
-attnumAttName(Relation rd, int attid)
-{
- if (attid <= 0)
- {
- Form_pg_attribute sysatt;
-
- sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids);
- return &sysatt->attname;
- }
- if (attid > rd->rd_att->natts)
- elog(ERROR, "attnumAttName: invalid attribute number %d", attid);
- return &rd->rd_att->attrs[attid - 1]->attname;
-}
-
-/*
- * given attribute id, return type of that attribute
- *
- * This should only be used if the relation is already
- * heap_open()'ed. Use the cache version get_atttype()
- * for access to non-opened relations.
- */
-Oid
-attnumTypeId(Relation rd, int attid)
-{
- if (attid <= 0)
- {
- Form_pg_attribute sysatt;
-
- sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids);
- return sysatt->atttypid;
- }
- if (attid > rd->rd_att->natts)
- elog(ERROR, "attnumTypeId: invalid attribute number %d", attid);
- return rd->rd_att->attrs[attid - 1]->atttypid;
-}
-
-/*
- * Generate a warning about an implicit RTE, if appropriate.
- *
- * Our current theory on this is that we should allow "SELECT foo.*"
- * but warn about a mixture of explicit and implicit RTEs.
- */
-static void
-warnAutoRange(ParseState *pstate, RangeVar *relation)
-{
- bool foundInFromCl = false;
- List *temp;
-
- foreach(temp, pstate->p_rtable)
- {
- RangeTblEntry *rte = lfirst(temp);
-
- if (rte->inFromCl)
- {
- foundInFromCl = true;
- break;
- }
- }
- if (foundInFromCl)
- elog(NOTICE, "Adding missing FROM-clause entry%s for table \"%s\"",
- pstate->parentParseState != NULL ? " in subquery" : "",
- relation->relname);
-}
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
deleted file mode 100644
index 608ca7613dc..00000000000
--- a/src/backend/parser/parse_target.c
+++ /dev/null
@@ -1,561 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_target.c
- * handle target lists
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.85 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "miscadmin.h"
-#include "nodes/makefuncs.h"
-#include "parser/parsetree.h"
-#include "parser/parse_coerce.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_func.h"
-#include "parser/parse_relation.h"
-#include "parser/parse_target.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-
-
-static List *ExpandAllTables(ParseState *pstate);
-static char *FigureColname(Node *node);
-static int FigureColnameInternal(Node *node, char **name);
-
-
-/*
- * transformTargetEntry()
- * Transform any ordinary "expression-type" node into a targetlist entry.
- * This is exported so that parse_clause.c can generate targetlist entries
- * for ORDER/GROUP BY items that are not already in the targetlist.
- *
- * node the (untransformed) parse tree for the value expression.
- * expr the transformed expression, or NULL if caller didn't do it yet.
- * colname the column name to be assigned, or NULL if none yet set.
- * resjunk true if the target should be marked resjunk, ie, it is not
- * wanted in the final projected tuple.
- */
-TargetEntry *
-transformTargetEntry(ParseState *pstate,
- Node *node,
- Node *expr,
- char *colname,
- bool resjunk)
-{
- Oid type_id;
- int32 type_mod;
- Resdom *resnode;
-
- /* Transform the node if caller didn't do it already */
- if (expr == NULL)
- expr = transformExpr(pstate, node);
-
- if (IsA(expr, RangeVar))
- elog(ERROR, "You can't use relation names alone in the target list, try relation.*.");
-
- type_id = exprType(expr);
- type_mod = exprTypmod(expr);
-
- if (colname == NULL)
- {
- /*
- * Generate a suitable column name for a column without any
- * explicit 'AS ColumnName' clause.
- */
- colname = FigureColname(node);
- }
-
- resnode = makeResdom((AttrNumber) pstate->p_last_resno++,
- type_id,
- type_mod,
- colname,
- resjunk);
-
- return makeTargetEntry(resnode, expr);
-}
-
-
-/*
- * transformTargetList()
- * Turns a list of ResTarget's into a list of TargetEntry's.
- *
- * At this point, we don't care whether we are doing SELECT, INSERT,
- * or UPDATE; we just transform the given expressions.
- */
-List *
-transformTargetList(ParseState *pstate, List *targetlist)
-{
- List *p_target = NIL;
-
- while (targetlist != NIL)
- {
- ResTarget *res = (ResTarget *) lfirst(targetlist);
-
- if (IsA(res->val, ColumnRef))
- {
- ColumnRef *cref = (ColumnRef *) res->val;
- List *fields = cref->fields;
- int numnames = length(fields);
-
- if (numnames == 1 && strcmp(strVal(lfirst(fields)), "*") == 0)
- {
- /*
- * Target item is a single '*', expand all tables (eg.
- * SELECT * FROM emp)
- */
- p_target = nconc(p_target,
- ExpandAllTables(pstate));
- }
- else if (strcmp(strVal(nth(numnames-1, fields)), "*") == 0)
- {
- /*
- * Target item is relation.*, expand that table (eg.
- * SELECT emp.*, dname FROM emp, dept)
- */
- char *schemaname;
- char *relname;
- RangeTblEntry *rte;
- int sublevels_up;
-
- switch (numnames)
- {
- case 2:
- schemaname = NULL;
- relname = strVal(lfirst(fields));
- break;
- case 3:
- schemaname = strVal(lfirst(fields));
- relname = strVal(lsecond(fields));
- break;
- case 4:
- {
- char *name1 = strVal(lfirst(fields));
-
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(name1, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- schemaname = strVal(lsecond(fields));
- relname = strVal(lfirst(lnext(lnext(fields))));
- break;
- }
- default:
- elog(ERROR, "Invalid qualified name syntax (too many names)");
- schemaname = NULL; /* keep compiler quiet */
- relname = NULL;
- break;
- }
-
- /* XXX do something with schema name */
- rte = refnameRangeTblEntry(pstate, relname,
- &sublevels_up);
- if (rte == NULL)
- rte = addImplicitRTE(pstate, makeRangeVar(NULL, relname));
-
- p_target = nconc(p_target,
- expandRelAttrs(pstate, rte));
- }
- else
- {
- /* Plain ColumnRef node, treat it as an expression */
- p_target = lappend(p_target,
- transformTargetEntry(pstate,
- res->val,
- NULL,
- res->name,
- false));
- }
- }
- else if (IsA(res->val, InsertDefault))
- {
- InsertDefault *newnode = makeNode(InsertDefault);
-
- /*
- * If this is a DEFAULT element, we make a junk entry
- * which will get dropped on return to transformInsertStmt().
- */
- p_target = lappend(p_target, newnode);
- }
- else
- {
- /* Everything else but ColumnRef and InsertDefault */
- p_target = lappend(p_target,
- transformTargetEntry(pstate,
- res->val,
- NULL,
- res->name,
- false));
- }
-
- targetlist = lnext(targetlist);
- }
-
- return p_target;
-}
-
-
-/*
- * updateTargetListEntry()
- * This is used in INSERT and UPDATE statements only. It prepares a
- * TargetEntry for assignment to a column of the target table.
- * This includes coercing the given value to the target column's type
- * (if necessary), and dealing with any subscripts attached to the target
- * column itself.
- *
- * pstate parse state
- * tle target list entry to be modified
- * colname target column name (ie, name of attribute to be assigned to)
- * attrno target attribute number
- * indirection subscripts for target column, if any
- */
-void
-updateTargetListEntry(ParseState *pstate,
- TargetEntry *tle,
- char *colname,
- int attrno,
- List *indirection)
-{
- Oid type_id = exprType(tle->expr); /* type of value provided */
- Oid attrtype; /* type of target column */
- int32 attrtypmod;
- Resdom *resnode = tle->resdom;
- Relation rd = pstate->p_target_relation;
-
- Assert(rd != NULL);
- if (attrno <= 0)
- elog(ERROR, "Cannot assign to system attribute '%s'", colname);
- attrtype = attnumTypeId(rd, attrno);
- attrtypmod = rd->rd_att->attrs[attrno - 1]->atttypmod;
-
- /*
- * If there are subscripts on the target column, prepare an array
- * assignment expression. This will generate an array value that the
- * source value has been inserted into, which can then be placed in
- * the new tuple constructed by INSERT or UPDATE. Note that
- * transformArraySubscripts takes care of type coercion.
- */
- if (indirection)
- {
- Node *arrayBase;
- ArrayRef *aref;
-
- if (pstate->p_is_insert)
- {
- /*
- * The command is INSERT INTO table (arraycol[subscripts]) ...
- * so there is not really a source array value to work with.
- * Let the executor do something reasonable, if it can. Notice
- * that we force transformArraySubscripts to treat the
- * subscripting op as an array-slice op below, so the source
- * data will have been coerced to the array type.
- */
- arrayBase = NULL; /* signal there is no source array */
- }
- else
- {
- /*
- * Build a Var for the array to be updated.
- */
- arrayBase = (Node *) make_var(pstate,
- pstate->p_target_rangetblentry,
- attrno);
- }
-
- aref = transformArraySubscripts(pstate,
- arrayBase,
- attrtype,
- indirection,
- pstate->p_is_insert,
- tle->expr);
- tle->expr = (Node *) aref;
- }
- else
- {
- /*
- * For normal non-subscripted target column, do type checking and
- * coercion. But accept InvalidOid, which indicates the source is
- * a NULL constant.
- */
- if (type_id != InvalidOid)
- {
- if (type_id != attrtype)
- {
- tle->expr = CoerceTargetExpr(pstate, tle->expr, type_id,
- attrtype, attrtypmod,
- false);
- if (tle->expr == NULL)
- elog(ERROR, "column \"%s\" is of type '%s'"
- " but expression is of type '%s'"
- "\n\tYou will need to rewrite or cast the expression",
- colname,
- format_type_be(attrtype),
- format_type_be(type_id));
- }
-
- /*
- * If the target is a fixed-length type, it may need a length
- * coercion as well as a type coercion.
- */
- tle->expr = coerce_type_typmod(pstate, tle->expr,
- attrtype, attrtypmod);
- }
- }
-
- /*
- * The result of the target expression should now match the
- * destination column's type. Also, reset the resname and resno to
- * identify the destination column --- rewriter and planner depend on
- * that!
- */
- resnode->restype = attrtype;
- resnode->restypmod = attrtypmod;
- resnode->resname = colname;
- resnode->resno = (AttrNumber) attrno;
-}
-
-
-Node *
-CoerceTargetExpr(ParseState *pstate,
- Node *expr,
- Oid type_id,
- Oid attrtype,
- int32 attrtypmod,
- bool isExplicit)
-{
- if (can_coerce_type(1, &type_id, &attrtype, isExplicit))
- expr = coerce_type(pstate, expr, type_id, attrtype, attrtypmod,
- isExplicit);
-
-#ifndef DISABLE_STRING_HACKS
-
- /*
- * string hacks to get transparent conversions w/o explicit
- * conversions
- */
- else if ((attrtype == BPCHAROID) || (attrtype == VARCHAROID))
- {
- Oid text_id = TEXTOID;
-
- if (type_id == TEXTOID)
- {
- }
- else if (can_coerce_type(1, &type_id, &text_id, isExplicit))
- expr = coerce_type(pstate, expr, type_id, text_id, attrtypmod,
- isExplicit);
- else
- expr = NULL;
- }
-#endif
-
- else
- expr = NULL;
-
- return expr;
-}
-
-
-/*
- * checkInsertTargets -
- * generate a list of INSERT column targets if not supplied, or
- * test supplied column names to make sure they are in target table.
- * Also return an integer list of the columns' attribute numbers.
- */
-List *
-checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
-{
- *attrnos = NIL;
-
- if (cols == NIL)
- {
- /*
- * Generate default column list for INSERT.
- */
- Form_pg_attribute *attr = pstate->p_target_relation->rd_att->attrs;
- int numcol = pstate->p_target_relation->rd_rel->relnatts;
- int i;
-
- for (i = 0; i < numcol; i++)
- {
- ResTarget *col = makeNode(ResTarget);
-
- col->name = pstrdup(NameStr(attr[i]->attname));
- col->indirection = NIL;
- col->val = NULL;
- cols = lappend(cols, col);
- *attrnos = lappendi(*attrnos, i + 1);
- }
- }
- else
- {
- /*
- * Do initial validation of user-supplied INSERT column list.
- */
- List *tl;
-
- foreach(tl, cols)
- {
- char *name = ((ResTarget *) lfirst(tl))->name;
- int attrno;
-
- /* Lookup column name, elog on failure */
- attrno = attnameAttNum(pstate->p_target_relation, name);
- /* Check for duplicates */
- if (intMember(attrno, *attrnos))
- elog(ERROR, "Attribute '%s' specified more than once", name);
- *attrnos = lappendi(*attrnos, attrno);
- }
- }
-
- return cols;
-}
-
-/* ExpandAllTables()
- * Turns '*' (in the target list) into a list of targetlist entries.
- *
- * tlist entries are generated for each relation appearing at the top level
- * of the query's namespace, except for RTEs marked not inFromCl. (These
- * may include NEW/OLD pseudo-entries, implicit RTEs, etc.)
- */
-static List *
-ExpandAllTables(ParseState *pstate)
-{
- List *target = NIL;
- List *ns;
-
- foreach(ns, pstate->p_namespace)
- {
- Node *n = (Node *) lfirst(ns);
- RangeTblEntry *rte;
-
- if (IsA(n, RangeTblRef))
- rte = rt_fetch(((RangeTblRef *) n)->rtindex,
- pstate->p_rtable);
- else if (IsA(n, JoinExpr))
- rte = rt_fetch(((JoinExpr *) n)->rtindex,
- pstate->p_rtable);
- else
- {
- elog(ERROR, "ExpandAllTables: unexpected node (internal error)"
- "\n\t%s", nodeToString(n));
- rte = NULL; /* keep compiler quiet */
- }
-
- /*
- * Ignore added-on relations that were not listed in the FROM
- * clause.
- */
- if (!rte->inFromCl)
- continue;
-
- target = nconc(target, expandRelAttrs(pstate, rte));
- }
-
- /* Check for SELECT *; */
- if (target == NIL)
- elog(ERROR, "Wildcard with no tables specified not allowed");
-
- return target;
-}
-
-/*
- * FigureColname -
- * if the name of the resulting column is not specified in the target
- * list, we have to guess a suitable name. The SQL spec provides some
- * guidance, but not much...
- *
- * Note that the argument is the *untransformed* parse tree for the target
- * item. This is a shade easier to work with than the transformed tree.
- */
-static char *
-FigureColname(Node *node)
-{
- char *name = NULL;
-
- FigureColnameInternal(node, &name);
- if (name != NULL)
- return name;
- /* default result if we can't guess anything */
- return "?column?";
-}
-
-static int
-FigureColnameInternal(Node *node, char **name)
-{
- int strength = 0;
-
- if (node == NULL)
- return strength;
-
- switch (nodeTag(node))
- {
- case T_Ident:
- *name = ((Ident *) node)->name;
- return 2;
- case T_ColumnRef:
- {
- char *cname = strVal(llast(((ColumnRef *) node)->fields));
-
- if (strcmp(cname, "*") != 0)
- {
- *name = cname;
- return 2;
- }
- }
- break;
- case T_ExprFieldSelect:
- {
- char *fname = strVal(llast(((ExprFieldSelect *) node)->fields));
-
- if (strcmp(fname, "*") != 0)
- {
- *name = fname;
- return 2;
- }
- }
- break;
- case T_FuncCall:
- *name = strVal(llast(((FuncCall *) node)->funcname));
- return 2;
- case T_A_Const:
- if (((A_Const *) node)->typename != NULL)
- {
- *name = strVal(llast(((A_Const *) node)->typename->names));
- return 1;
- }
- break;
- case T_TypeCast:
- strength = FigureColnameInternal(((TypeCast *) node)->arg,
- name);
- if (strength <= 1)
- {
- if (((TypeCast *) node)->typename != NULL)
- {
- *name = strVal(llast(((TypeCast *) node)->typename->names));
- return 1;
- }
- }
- break;
- case T_CaseExpr:
- strength = FigureColnameInternal(((CaseExpr *) node)->defresult,
- name);
- if (strength <= 1)
- {
- *name = "case";
- return 1;
- }
- break;
- default:
- break;
- }
-
- return strength;
-}
diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c
deleted file mode 100644
index 04cefb29904..00000000000
--- a/src/backend/parser/parse_type.c
+++ /dev/null
@@ -1,505 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parse_type.c
- * handle type operations for parser
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.43 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "catalog/namespace.h"
-#include "catalog/pg_type.h"
-#include "lib/stringinfo.h"
-#include "miscadmin.h"
-#include "nodes/makefuncs.h"
-#include "nodes/parsenodes.h"
-#include "parser/parser.h"
-#include "parser/parse_expr.h"
-#include "parser/parse_type.h"
-#include "utils/builtins.h"
-#include "utils/lsyscache.h"
-#include "utils/syscache.h"
-
-
-/*
- * LookupTypeName
- * Given a TypeName object, get the OID of the referenced type.
- * Returns InvalidOid if no such type can be found.
- *
- * NB: even if the returned OID is not InvalidOid, the type might be
- * just a shell. Caller should check typisdefined before using the type.
- */
-Oid
-LookupTypeName(const TypeName *typename)
-{
- Oid restype;
-
- /* Easy if it's an internally generated TypeName */
- if (typename->names == NIL)
- return typename->typeid;
-
- if (typename->pct_type)
- {
- /* Handle %TYPE reference to type of an existing field */
- RangeVar *rel = makeRangeVar(NULL, NULL);
- char *field = NULL;
- Oid relid;
- AttrNumber attnum;
-
- /* deconstruct the name list */
- switch (length(typename->names))
- {
- case 1:
- elog(ERROR, "Improper %%TYPE reference (too few dotted names): %s",
- NameListToString(typename->names));
- break;
- case 2:
- rel->relname = strVal(lfirst(typename->names));
- field = strVal(lsecond(typename->names));
- break;
- case 3:
- rel->schemaname = strVal(lfirst(typename->names));
- rel->relname = strVal(lsecond(typename->names));
- field = strVal(lfirst(lnext(lnext(typename->names))));
- break;
- case 4:
- rel->catalogname = strVal(lfirst(typename->names));
- rel->schemaname = strVal(lsecond(typename->names));
- rel->relname = strVal(lfirst(lnext(lnext(typename->names))));
- field = strVal(lfirst(lnext(lnext(lnext(typename->names)))));
- break;
- default:
- elog(ERROR, "Improper %%TYPE reference (too many dotted names): %s",
- NameListToString(typename->names));
- break;
- }
-
- /* look up the field */
- relid = RangeVarGetRelid(rel, false);
- attnum = get_attnum(relid, field);
- if (attnum == InvalidAttrNumber)
- elog(ERROR, "'%s' is not an attribute of class '%s'",
- field, rel->relname);
- restype = get_atttype(relid, attnum);
-
- /* this construct should never have an array indicator */
- Assert(typename->arrayBounds == NIL);
-
- /* emit nuisance warning */
- elog(NOTICE, "%s converted to %s",
- TypeNameToString(typename), format_type_be(restype));
- }
- else
- {
- /* Normal reference to a type name */
- char *catalogname;
- char *schemaname = NULL;
- char *typname = NULL;
-
- /* deconstruct the name list */
- switch (length(typename->names))
- {
- case 1:
- typname = strVal(lfirst(typename->names));
- break;
- case 2:
- schemaname = strVal(lfirst(typename->names));
- typname = strVal(lsecond(typename->names));
- break;
- case 3:
- catalogname = strVal(lfirst(typename->names));
- schemaname = strVal(lsecond(typename->names));
- typname = strVal(lfirst(lnext(lnext(typename->names))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper type name (too many dotted names): %s",
- NameListToString(typename->names));
- break;
- }
-
- /* If an array reference, look up the array type instead */
- if (typename->arrayBounds != NIL)
- typname = makeArrayTypeName(typname);
-
- if (schemaname)
- {
- /* Look in specific schema only */
- Oid namespaceId;
-
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
- restype = GetSysCacheOid(TYPENAMENSP,
- PointerGetDatum(typname),
- ObjectIdGetDatum(namespaceId),
- 0, 0);
- }
- else
- {
- /* Unqualified type name, so search the search path */
- restype = TypenameGetTypid(typname);
- }
- }
-
- return restype;
-}
-
-/*
- * TypeNameToString
- * Produce a string representing the name of a TypeName.
- *
- * NB: this must work on TypeNames that do not describe any actual type;
- * it is mostly used for reporting lookup errors.
- */
-char *
-TypeNameToString(const TypeName *typename)
-{
- StringInfoData string;
-
- initStringInfo(&string);
-
- if (typename->names != NIL)
- {
- /* Emit possibly-qualified name as-is */
- List *l;
-
- foreach(l, typename->names)
- {
- if (l != typename->names)
- appendStringInfoChar(&string, '.');
- appendStringInfo(&string, "%s", strVal(lfirst(l)));
- }
- }
- else
- {
- /* Look up internally-specified type */
- appendStringInfo(&string, "%s", format_type_be(typename->typeid));
- }
-
- /*
- * Add decoration as needed, but only for fields considered by
- * LookupTypeName
- */
- if (typename->pct_type)
- appendStringInfo(&string, "%%TYPE");
-
- if (typename->arrayBounds != NIL)
- appendStringInfo(&string, "[]");
-
- return string.data;
-}
-
-/*
- * typenameTypeId - given a TypeName, return the type's OID
- *
- * This is equivalent to LookupTypeName, except that this will report
- * a suitable error message if the type cannot be found or is not defined.
- */
-Oid
-typenameTypeId(const TypeName *typename)
-{
- Oid typoid;
-
- typoid = LookupTypeName(typename);
- if (!OidIsValid(typoid))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(typename));
- if (!get_typisdefined(typoid))
- elog(ERROR, "Type \"%s\" is only a shell",
- TypeNameToString(typename));
- return typoid;
-}
-
-/*
- * typenameType - given a TypeName, return a Type structure
- *
- * This is equivalent to typenameTypeId + syscache fetch of Type tuple.
- * NB: caller must ReleaseSysCache the type tuple when done with it.
- */
-Type
-typenameType(const TypeName *typename)
-{
- Oid typoid;
- HeapTuple tup;
-
- typoid = LookupTypeName(typename);
- if (!OidIsValid(typoid))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(typename));
- tup = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(typoid),
- 0, 0, 0);
- if (!HeapTupleIsValid(tup))
- elog(ERROR, "Type \"%s\" does not exist",
- TypeNameToString(typename));
- if (! ((Form_pg_type) GETSTRUCT(tup))->typisdefined)
- elog(ERROR, "Type \"%s\" is only a shell",
- TypeNameToString(typename));
- return (Type) tup;
-}
-
-/* check to see if a type id is valid, returns true if it is */
-bool
-typeidIsValid(Oid id)
-{
- return SearchSysCacheExists(TYPEOID,
- ObjectIdGetDatum(id),
- 0, 0, 0);
-}
-
-/* return a Type structure, given a type id */
-/* NB: caller must ReleaseSysCache the type tuple when done with it */
-Type
-typeidType(Oid id)
-{
- HeapTuple tup;
-
- tup = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(id),
- 0, 0, 0);
- if (!HeapTupleIsValid(tup))
- elog(ERROR, "Unable to locate type oid %u in catalog", id);
- return (Type) tup;
-}
-
-/* given type (as type struct), return the type OID */
-Oid
-typeTypeId(Type tp)
-{
- if (tp == NULL)
- elog(ERROR, "typeTypeId() called with NULL type struct");
- return tp->t_data->t_oid;
-}
-
-/* given type (as type struct), return the length of type */
-int16
-typeLen(Type t)
-{
- Form_pg_type typ;
-
- typ = (Form_pg_type) GETSTRUCT(t);
- return typ->typlen;
-}
-
-/* given type (as type struct), return the value of its 'byval' attribute.*/
-bool
-typeByVal(Type t)
-{
- Form_pg_type typ;
-
- typ = (Form_pg_type) GETSTRUCT(t);
- return typ->typbyval;
-}
-
-/* given type (as type struct), return the name of type */
-char *
-typeTypeName(Type t)
-{
- Form_pg_type typ;
-
- typ = (Form_pg_type) GETSTRUCT(t);
- /* pstrdup here because result may need to outlive the syscache entry */
- return pstrdup(NameStr(typ->typname));
-}
-
-/* given a type, return its typetype ('c' for 'c'atalog types) */
-char
-typeTypeFlag(Type t)
-{
- Form_pg_type typ;
-
- typ = (Form_pg_type) GETSTRUCT(t);
- return typ->typtype;
-}
-
-Oid
-typeTypeRelid(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typrelid;
-}
-
-#ifdef NOT_USED
-Oid
-typeTypElem(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typelem;
-}
-#endif
-
-#ifdef NOT_USED
-/* Given a type structure, return the in-conversion function of the type */
-Oid
-typeInfunc(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typinput;
-}
-#endif
-
-#ifdef NOT_USED
-/* Given a type structure, return the out-conversion function of the type */
-Oid
-typeOutfunc(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typoutput;
-}
-#endif
-
-/* Given a type structure and a string, returns the internal form of
- that string */
-Datum
-stringTypeDatum(Type tp, char *string, int32 atttypmod)
-{
- Oid op;
- Oid typelem;
-
- op = ((Form_pg_type) GETSTRUCT(tp))->typinput;
- typelem = ((Form_pg_type) GETSTRUCT(tp))->typelem; /* XXX - used for
- * array_in */
- return OidFunctionCall3(op,
- CStringGetDatum(string),
- ObjectIdGetDatum(typelem),
- Int32GetDatum(atttypmod));
-}
-
-/* Given a type id, returns the out-conversion function of the type */
-#ifdef NOT_USED
-Oid
-typeidOutfunc(Oid type_id)
-{
- HeapTuple typeTuple;
- Form_pg_type type;
- Oid outfunc;
-
- typeTuple = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(type_id),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTuple))
- elog(ERROR, "typeidOutfunc: Invalid type - oid = %u", type_id);
-
- type = (Form_pg_type) GETSTRUCT(typeTuple);
- outfunc = type->typoutput;
- ReleaseSysCache(typeTuple);
- return outfunc;
-}
-#endif
-
-/* given a typeid, return the type's typrelid (associated relation, if any) */
-Oid
-typeidTypeRelid(Oid type_id)
-{
- HeapTuple typeTuple;
- Form_pg_type type;
- Oid result;
-
- typeTuple = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(type_id),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTuple))
- elog(ERROR, "typeidTypeRelid: Invalid type - oid = %u", type_id);
-
- type = (Form_pg_type) GETSTRUCT(typeTuple);
- result = type->typrelid;
- ReleaseSysCache(typeTuple);
- return result;
-}
-
-/*
- * Given a string that is supposed to be a SQL-compatible type declaration,
- * such as "int4" or "integer" or "character varying(32)", parse
- * the string and convert it to a type OID and type modifier.
- *
- * This routine is not currently used by the main backend, but it is
- * exported for use by add-on modules such as plpgsql, in hopes of
- * centralizing parsing knowledge about SQL type declarations.
- */
-void
-parseTypeString(const char *str, Oid *type_id, int32 *typmod)
-{
- StringInfoData buf;
- List *raw_parsetree_list;
- SelectStmt *stmt;
- ResTarget *restarget;
- A_Const *aconst;
- TypeName *typename;
-
- initStringInfo(&buf);
- appendStringInfo(&buf, "SELECT (NULL::%s)", str);
-
- raw_parsetree_list = parser(&buf, NULL, 0);
-
- /*
- * Make sure we got back exactly what we expected and no more;
- * paranoia is justified since the string might contain anything.
- */
- if (length(raw_parsetree_list) != 1)
- elog(ERROR, "Invalid type name '%s'", str);
- stmt = (SelectStmt *) lfirst(raw_parsetree_list);
- if (stmt == NULL ||
- !IsA(stmt, SelectStmt) ||
- stmt->distinctClause != NIL ||
- stmt->into != NULL ||
- stmt->fromClause != NIL ||
- stmt->whereClause != NULL ||
- stmt->groupClause != NIL ||
- stmt->havingClause != NULL ||
- stmt->sortClause != NIL ||
- stmt->portalname != NULL ||
- stmt->limitOffset != NULL ||
- stmt->limitCount != NULL ||
- stmt->forUpdate != NIL ||
- stmt->op != SETOP_NONE)
- elog(ERROR, "Invalid type name '%s'", str);
- if (length(stmt->targetList) != 1)
- elog(ERROR, "Invalid type name '%s'", str);
- restarget = (ResTarget *) lfirst(stmt->targetList);
- if (restarget == NULL ||
- !IsA(restarget, ResTarget) ||
- restarget->name != NULL ||
- restarget->indirection != NIL)
- elog(ERROR, "Invalid type name '%s'", str);
- aconst = (A_Const *) restarget->val;
- if (aconst == NULL ||
- !IsA(aconst, A_Const) ||
- aconst->val.type != T_Null)
- elog(ERROR, "Invalid type name '%s'", str);
- typename = aconst->typename;
- if (typename == NULL ||
- !IsA(typename, TypeName))
- elog(ERROR, "Invalid type name '%s'", str);
-
- *type_id = typenameTypeId(typename);
- *typmod = typename->typmod;
-
- pfree(buf.data);
-}
diff --git a/src/backend/parser/parser.c b/src/backend/parser/parser.c
deleted file mode 100644
index f4cd24e0c4f..00000000000
--- a/src/backend/parser/parser.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * parser.c
- * Main entry point/driver for PostgreSQL grammar
- *
- * Note that the grammar is not allowed to perform any table access
- * (since we need to be able to do basic parsing even while inside an
- * aborted transaction). Therefore, the data structures returned by
- * the grammar are "raw" parsetrees that still need to be analyzed by
- * parse_analyze.
- *
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.53 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "nodes/parsenodes.h"
-#include "parser/gramparse.h"
-#include "parser/parse.h"
-#include "parser/parser.h"
-#include "parser/parse_expr.h"
-
-
-List *parsetree; /* result of parsing is left here */
-
-static int lookahead_token; /* one-token lookahead */
-static bool have_lookahead; /* lookahead_token set? */
-
-
-/*
- * parser
- * Given a query in string form, and optionally info about
- * parameter types, do lexical and syntactic analysis.
- *
- * Returns a list of raw (un-analyzed) parse trees.
- */
-List *
-parser(StringInfo str, Oid *typev, int nargs)
-{
- int yyresult;
-
- parsetree = NIL; /* in case parser forgets to set it */
- have_lookahead = false;
-
- scanner_init(str);
- parser_init(typev, nargs);
- parse_expr_init();
-
- yyresult = yyparse();
-
- scanner_finish();
- clearerr(stdin);
-
- if (yyresult) /* error */
- return NIL;
-
- return parsetree;
-}
-
-
-/*
- * Intermediate filter between parser and base lexer (base_yylex in scan.l).
- *
- * The filter is needed because in some cases SQL92 requires more than one
- * token lookahead. We reduce these cases to one-token lookahead by combining
- * tokens here, in order to keep the grammar LR(1).
- *
- * Using a filter is simpler than trying to recognize multiword tokens
- * directly in scan.l, because we'd have to allow for comments between the
- * words ...
- */
-int
-yylex(void)
-{
- int cur_token;
-
- /* Get next token --- we might already have it */
- if (have_lookahead)
- {
- cur_token = lookahead_token;
- have_lookahead = false;
- }
- else
- cur_token = base_yylex();
-
- /* Do we need to look ahead for a possible multiword token? */
- switch (cur_token)
- {
- case UNION:
- /* UNION JOIN must be reduced to a single UNIONJOIN token */
- lookahead_token = base_yylex();
- if (lookahead_token == JOIN)
- cur_token = UNIONJOIN;
- else
- have_lookahead = true;
- break;
-
- default:
- break;
- }
-
- return cur_token;
-}
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
deleted file mode 100644
index 1f73ec47a92..00000000000
--- a/src/backend/parser/scan.l
+++ /dev/null
@@ -1,666 +0,0 @@
-%{
-/*-------------------------------------------------------------------------
- *
- * scan.l
- * lexical scanner for PostgreSQL
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.96 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include <ctype.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "miscadmin.h"
-#include "nodes/parsenodes.h"
-#include "nodes/pg_list.h"
-#include "parser/gramparse.h"
-#include "parser/keywords.h"
-#include "parser/parse.h"
-#include "utils/builtins.h"
-
-#ifdef MULTIBYTE
-#include "mb/pg_wchar.h"
-#endif
-
-/* No reason to constrain amount of data slurped */
-#define YY_READ_BUF_SIZE 16777216
-
-/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
-#define fprintf(file, fmt, msg) elog(FATAL, "%s", (msg))
-
-extern YYSTYPE yylval;
-
-static int xcdepth = 0; /* depth of nesting in slash-star comments */
-
-/*
- * literalbuf is used to accumulate literal values when multiple rules
- * are needed to parse a single literal. Call startlit to reset buffer
- * to empty, addlit to add text. Note that the buffer is palloc'd and
- * starts life afresh on every parse cycle.
- */
-static char *literalbuf; /* expandable buffer */
-static int literallen; /* actual current length */
-static int literalalloc; /* current allocated buffer size */
-
-#define startlit() (literalbuf[0] = '\0', literallen = 0)
-static void addlit(char *ytext, int yleng);
-static void addlitchar(unsigned char ychar);
-static char *litbufdup(void);
-
-/*
- * When we parse a token that requires multiple lexer rules to process,
- * we set token_start to point at the true start of the token, for use
- * by yyerror(). yytext will point at just the text consumed by the last
- * rule, so it's not very helpful (eg, it might contain just the last
- * quote mark of a quoted identifier). But to avoid cluttering every rule
- * with setting token_start, we allow token_start = NULL to denote that
- * it's okay to use yytext.
- */
-static char *token_start;
-
-/* Handles to the buffer that the lexer uses internally */
-static YY_BUFFER_STATE scanbufhandle;
-static char *scanbuf;
-
-unsigned char unescape_single_char(unsigned char c);
-
-%}
-
-%option 8bit
-%option never-interactive
-%option nounput
-%option noyywrap
-%option prefix="base_yy"
-
-/*
- * OK, here is a short description of lex/flex rules behavior.
- * The longest pattern which matches an input string is always chosen.
- * For equal-length patterns, the first occurring in the rules list is chosen.
- * INITIAL is the starting state, to which all non-conditional rules apply.
- * Exclusive states change parsing rules while the state is active. When in
- * an exclusive state, only those rules defined for that state apply.
- *
- * We use exclusive states for quoted strings, extended comments,
- * and to eliminate parsing troubles for numeric strings.
- * Exclusive states:
- * <xb> bit string literal
- * <xc> extended C-style comments - thomas 1997-07-12
- * <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
- * <xh> hexadecimal numeric string - thomas 1997-11-16
- * <xq> quoted strings - thomas 1997-07-30
- */
-
-%x xb
-%x xc
-%x xd
-%x xh
-%x xq
-
-/* Bit string
- */
-xbstart [bB]{quote}
-xbstop {quote}
-xbinside [^']*
-xbcat {quote}{whitespace_with_newline}{quote}
-
-/* Hexadecimal number
- */
-xhstart [xX]{quote}
-xhstop {quote}
-xhinside [^']+
-xhcat {quote}{whitespace_with_newline}{quote}
-
-/* Extended quote
- * xqdouble implements SQL92 embedded quote
- * xqcat allows strings to cross input lines
- */
-quote '
-xqstart {quote}
-xqstop {quote}
-xqdouble {quote}{quote}
-xqinside [^\\']+
-xqescape [\\][^0-7]
-xqoctesc [\\][0-7]{1,3}
-xqcat {quote}{whitespace_with_newline}{quote}
-
-/* Double quote
- * Allows embedded spaces and other special characters into identifiers.
- */
-dquote \"
-xdstart {dquote}
-xdstop {dquote}
-xddouble {dquote}{dquote}
-xdinside [^"]+
-
-/* C-style comments
- *
- * The "extended comment" syntax closely resembles allowable operator syntax.
- * The tricky part here is to get lex to recognize a string starting with
- * slash-star as a comment, when interpreting it as an operator would produce
- * a longer match --- remember lex will prefer a longer match! Also, if we
- * have something like plus-slash-star, lex will think this is a 3-character
- * operator whereas we want to see it as a + operator and a comment start.
- * The solution is two-fold:
- * 1. append {op_chars}* to xcstart so that it matches as much text as
- * {operator} would. Then the tie-breaker (first matching rule of same
- * length) ensures xcstart wins. We put back the extra stuff with yyless()
- * in case it contains a star-slash that should terminate the comment.
- * 2. In the operator rule, check for slash-star within the operator, and
- * if found throw it back with yyless(). This handles the plus-slash-star
- * problem.
- * SQL92-style comments, which start with dash-dash, have similar interactions
- * with the operator rule.
- */
-xcstart \/\*{op_chars}*
-xcstop \*+\/
-xcinside [^*/]+
-
-digit [0-9]
-letter [\200-\377_A-Za-z]
-letter_or_digit [\200-\377_A-Za-z0-9]
-
-identifier {letter}{letter_or_digit}*
-
-typecast "::"
-
-/*
- * "self" is the set of chars that should be returned as single-character
- * tokens. "op_chars" is the set of chars that can make up "Op" tokens,
- * which can be one or more characters long (but if a single-char token
- * appears in the "self" set, it is not to be returned as an Op). Note
- * that the sets overlap, but each has some chars that are not in the other.
- *
- * If you change either set, adjust the character lists appearing in the
- * rule for "operator"!
- */
-self [,()\[\].;$\:\+\-\*\/\%\^\<\>\=]
-op_chars [\~\!\@\#\^\&\|\`\?\$\+\-\*\/\%\<\>\=]
-operator {op_chars}+
-
-/* we no longer allow unary minus in numbers.
- * instead we pass it separately to parser. there it gets
- * coerced via doNegate() -- Leon aug 20 1999
- */
-
-integer {digit}+
-decimal (({digit}*\.{digit}+)|({digit}+\.{digit}*))
-real ((({digit}*\.{digit}+)|({digit}+\.{digit}*)|({digit}+))([Ee][-+]?{digit}+))
-
-param \${integer}
-
-/*
- * In order to make the world safe for Windows and Mac clients as well as
- * Unix ones, we accept either \n or \r as a newline. A DOS-style \r\n
- * sequence will be seen as two successive newlines, but that doesn't cause
- * any problems. SQL92-style comments, which start with -- and extend to the
- * next newline, are treated as equivalent to a single whitespace character.
- *
- * NOTE a fine point: if there is no newline following --, we will absorb
- * everything to the end of the input as a comment. This is correct. Older
- * versions of Postgres failed to recognize -- as a comment if the input
- * did not end with a newline.
- *
- * XXX perhaps \f (formfeed) should be treated as a newline as well?
- */
-
-space [ \t\n\r\f]
-horiz_space [ \t\f]
-newline [\n\r]
-non_newline [^\n\r]
-
-comment ("--"{non_newline}*)
-
-whitespace ({space}+|{comment})
-
-/*
- * SQL92 requires at least one newline in the whitespace separating
- * string literals that are to be concatenated. Silly, but who are we
- * to argue? Note that {whitespace_with_newline} should not have * after
- * it, whereas {whitespace} should generally have a * after it...
- */
-
-horiz_whitespace ({horiz_space}|{comment})
-whitespace_with_newline ({horiz_whitespace}*{newline}{whitespace}*)
-
-other .
-
-/*
- * Quoted strings must allow some special characters such as single-quote
- * and newline.
- * Embedded single-quotes are implemented both in the SQL92-standard
- * style of two adjacent single quotes "''" and in the Postgres/Java style
- * of escaped-quote "\'".
- * Other embedded escaped characters are matched explicitly and the leading
- * backslash is dropped from the string. - thomas 1997-09-24
- * Note that xcstart must appear before operator, as explained above!
- * Also whitespace (comment) must appear before operator.
- */
-
-%%
-
-%{
- /* code to execute during start of each call of yylex() */
- token_start = NULL;
-%}
-
-{whitespace} { /* ignore */ }
-
-{xcstart} {
- token_start = yytext;
- xcdepth = 0;
- BEGIN(xc);
- /* Put back any characters past slash-star; see above */
- yyless(2);
- }
-
-<xc>{xcstart} {
- xcdepth++;
- /* Put back any characters past slash-star; see above */
- yyless(2);
- }
-
-<xc>{xcstop} {
- if (xcdepth <= 0)
- {
- BEGIN(INITIAL);
- /* reset token_start for next token */
- token_start = NULL;
- }
- else
- xcdepth--;
- }
-
-<xc>{xcinside} { /* ignore */ }
-
-<xc>{op_chars} { /* ignore */ }
-
-<xc><<EOF>> { yyerror("unterminated /* comment"); }
-
-{xbstart} {
- token_start = yytext;
- BEGIN(xb);
- startlit();
- addlitchar('b');
- }
-<xb>{xbstop} {
- BEGIN(INITIAL);
- if (literalbuf[strspn(literalbuf + 1, "01") + 1] != '\0')
- yyerror("invalid bit string input");
- yylval.str = litbufdup();
- return BITCONST;
- }
-<xh>{xhinside} |
-<xb>{xbinside} {
- addlit(yytext, yyleng);
- }
-<xh>{xhcat} |
-<xb>{xbcat} {
- /* ignore */
- }
-<xb><<EOF>> { yyerror("unterminated bit string literal"); }
-
-{xhstart} {
- token_start = yytext;
- BEGIN(xh);
- startlit();
- }
-<xh>{xhstop} {
- long val;
- char* endptr;
-
- BEGIN(INITIAL);
- errno = 0;
- val = strtol(literalbuf, &endptr, 16);
- if (*endptr != '\0' || errno == ERANGE
-#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
- || val != (long) ((int32) val)
-#endif
- )
- yyerror("bad hexadecimal integer input");
- yylval.ival = val;
- return ICONST;
- }
-<xh><<EOF>> { yyerror("unterminated hexadecimal integer"); }
-
-{xqstart} {
- token_start = yytext;
- BEGIN(xq);
- startlit();
- }
-<xq>{xqstop} {
- BEGIN(INITIAL);
- yylval.str = litbufdup();
- return SCONST;
- }
-<xq>{xqdouble} {
- addlitchar('\'');
- }
-<xq>{xqinside} {
- addlit(yytext, yyleng);
- }
-<xq>{xqescape} {
- addlitchar(unescape_single_char(yytext[1]));
- }
-<xq>{xqoctesc} {
- unsigned char c = strtoul(yytext+1, NULL, 8);
- addlitchar(c);
- }
-<xq>{xqcat} {
- /* ignore */
- }
-<xq><<EOF>> { yyerror("unterminated quoted string"); }
-
-
-{xdstart} {
- token_start = yytext;
- BEGIN(xd);
- startlit();
- }
-<xd>{xdstop} {
- BEGIN(INITIAL);
- if (literallen == 0)
- yyerror("zero-length delimited identifier");
- if (literallen >= NAMEDATALEN)
- {
- int len;
-#ifdef MULTIBYTE
- len = pg_mbcliplen(literalbuf, literallen,
- NAMEDATALEN-1);
-#else
- len = NAMEDATALEN-1;
-#endif
- elog(NOTICE, "identifier \"%s\" will be truncated to \"%.*s\"",
- literalbuf, len, literalbuf);
- literalbuf[len] = '\0';
- literallen = len;
- }
- yylval.str = litbufdup();
- return IDENT;
- }
-<xd>{xddouble} {
- addlitchar('"');
- }
-<xd>{xdinside} {
- addlit(yytext, yyleng);
- }
-<xd><<EOF>> { yyerror("unterminated quoted identifier"); }
-
-{typecast} { return TYPECAST; }
-
-{self} { return yytext[0]; }
-
-{operator} {
- /*
- * Check for embedded slash-star or dash-dash; those
- * are comment starts, so operator must stop there.
- * Note that slash-star or dash-dash at the first
- * character will match a prior rule, not this one.
- */
- int nchars = yyleng;
- char *slashstar = strstr(yytext, "/*");
- char *dashdash = strstr(yytext, "--");
-
- if (slashstar && dashdash)
- {
- /* if both appear, take the first one */
- if (slashstar > dashdash)
- slashstar = dashdash;
- }
- else if (!slashstar)
- slashstar = dashdash;
- if (slashstar)
- nchars = slashstar - yytext;
-
- /*
- * For SQL92 compatibility, '+' and '-' cannot be the
- * last char of a multi-char operator unless the operator
- * contains chars that are not in SQL92 operators.
- * The idea is to lex '=-' as two operators, but not
- * to forbid operator names like '?-' that could not be
- * sequences of SQL92 operators.
- */
- while (nchars > 1 &&
- (yytext[nchars-1] == '+' ||
- yytext[nchars-1] == '-'))
- {
- int ic;
-
- for (ic = nchars-2; ic >= 0; ic--)
- {
- if (strchr("~!@#^&|`?$%", yytext[ic]))
- break;
- }
- if (ic >= 0)
- break; /* found a char that makes it OK */
- nchars--; /* else remove the +/-, and check again */
- }
-
- if (nchars < yyleng)
- {
- /* Strip the unwanted chars from the token */
- yyless(nchars);
- /*
- * If what we have left is only one char, and it's
- * one of the characters matching "self", then
- * return it as a character token the same way
- * that the "self" rule would have.
- */
- if (nchars == 1 &&
- strchr(",()[].;$:+-*/%^<>=", yytext[0]))
- return yytext[0];
- }
-
- /* Convert "!=" operator to "<>" for compatibility */
- if (strcmp(yytext, "!=") == 0)
- yylval.str = pstrdup("<>");
- else
- yylval.str = pstrdup(yytext);
- return Op;
- }
-
-{param} {
- yylval.ival = atol(yytext + 1);
- return PARAM;
- }
-
-{integer} {
- long val;
- char* endptr;
-
- errno = 0;
- val = strtol(yytext, &endptr, 10);
- if (*endptr != '\0' || errno == ERANGE
-#ifdef HAVE_LONG_INT_64
- /* if long > 32 bits, check for overflow of int4 */
- || val != (long) ((int32) val)
-#endif
- )
- {
- /* integer too large, treat it as a float */
- yylval.str = pstrdup(yytext);
- return FCONST;
- }
- yylval.ival = val;
- return ICONST;
- }
-{decimal} {
- yylval.str = pstrdup(yytext);
- return FCONST;
- }
-{real} {
- yylval.str = pstrdup(yytext);
- return FCONST;
- }
-
-
-{identifier} {
- const ScanKeyword *keyword;
- char *ident;
- int i;
-
- /* Is it a keyword? */
- keyword = ScanKeywordLookup(yytext);
- if (keyword != NULL)
- {
- yylval.keyword = keyword->name;
- return keyword->value;
- }
-
- /*
- * No. Convert the identifier to lower case, and truncate
- * if necessary.
- *
- * Note: here we use a locale-dependent case conversion,
- * which seems appropriate under SQL99 rules, whereas
- * the keyword comparison was NOT locale-dependent.
- */
- ident = pstrdup(yytext);
- for (i = 0; ident[i]; i++)
- {
- if (isupper((unsigned char) ident[i]))
- ident[i] = tolower((unsigned char) ident[i]);
- }
- if (i >= NAMEDATALEN)
- {
- int len;
-#ifdef MULTIBYTE
- len = pg_mbcliplen(ident, i, NAMEDATALEN-1);
-#else
- len = NAMEDATALEN-1;
-#endif
- elog(NOTICE, "identifier \"%s\" will be truncated to \"%.*s\"",
- ident, len, ident);
- ident[len] = '\0';
- }
- yylval.str = ident;
- return IDENT;
- }
-
-{other} { return yytext[0]; }
-
-%%
-
-void
-yyerror(const char *message)
-{
- elog(ERROR, "parser: %s at or near \"%s\"", message,
- token_start ? token_start : yytext);
-}
-
-
-/*
- * Called before any actual parsing is done
- */
-void
-scanner_init(StringInfo str)
-{
- /*
- * Might be left over after elog()
- */
- if (YY_CURRENT_BUFFER)
- yy_delete_buffer(YY_CURRENT_BUFFER);
-
- scanbuf = palloc(str->len + 2);
- memcpy(scanbuf, str->data, str->len);
- scanbuf[str->len] = scanbuf[str->len + 1] = YY_END_OF_BUFFER_CHAR;
- scanbufhandle = yy_scan_buffer(scanbuf, str->len + 2);
-
- /* initialize literal buffer to a reasonable but expansible size */
- literalalloc = 128;
- literalbuf = (char *) palloc(literalalloc);
- startlit();
-
- BEGIN(INITIAL);
-}
-
-
-/*
- * Called after parsing is done to clean up after scanner_init()
- */
-void
-scanner_finish(void)
-{
- yy_delete_buffer(scanbufhandle);
- pfree(scanbuf);
-}
-
-
-static void
-addlit(char *ytext, int yleng)
-{
- /* enlarge buffer if needed */
- if ((literallen+yleng) >= literalalloc)
- {
- do {
- literalalloc *= 2;
- } while ((literallen+yleng) >= literalalloc);
- literalbuf = (char *) repalloc(literalbuf, literalalloc);
- }
- /* append new data, add trailing null */
- memcpy(literalbuf+literallen, ytext, yleng);
- literallen += yleng;
- literalbuf[literallen] = '\0';
-}
-
-
-static void
-addlitchar(unsigned char ychar)
-{
- /* enlarge buffer if needed */
- if ((literallen+1) >= literalalloc)
- {
- literalalloc *= 2;
- literalbuf = (char *) repalloc(literalbuf, literalalloc);
- }
- /* append new data, add trailing null */
- literalbuf[literallen] = ychar;
- literallen += 1;
- literalbuf[literallen] = '\0';
-}
-
-
-/*
- * One might be tempted to write pstrdup(literalbuf) instead of this,
- * but for long literals this is much faster because the length is
- * already known.
- */
-static char *
-litbufdup(void)
-{
- char *new;
-
- new = palloc(literallen + 1);
- memcpy(new, literalbuf, literallen+1);
- return new;
-}
-
-
-unsigned char
-unescape_single_char(unsigned char c)
-{
- switch (c)
- {
- case 'b':
- return '\b';
- case 'f':
- return '\f';
- case 'n':
- return '\n';
- case 'r':
- return '\r';
- case 't':
- return '\t';
- default:
- return c;
- }
-}
diff --git a/src/backend/parser/scansup.c b/src/backend/parser/scansup.c
deleted file mode 100644
index be1b5ad136c..00000000000
--- a/src/backend/parser/scansup.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * scansup.c
- * support routines for the lex/flex scanner, used by both the normal
- * backend as well as the bootstrap backend
- *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.22 2002/06/20 20:29:33 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-
-#include <ctype.h>
-
-#include "postgres.h"
-#include "miscadmin.h"
-#include "parser/scansup.h"
-
-/* ----------------
- * scanstr
- *
- * if the string passed in has escaped codes, map the escape codes to actual
- * chars
- *
- * the string returned is palloc'd and should eventually be pfree'd by the
- * caller!
- * ----------------
- */
-
-char *
-scanstr(char *s)
-{
- char *newStr;
- int len,
- i,
- j;
-
- if (s == NULL || s[0] == '\0')
- return pstrdup("");
-
- len = strlen(s);
-
- newStr = palloc(len + 1); /* string cannot get longer */
-
- for (i = 0, j = 0; i < len; i++)
- {
- if (s[i] == '\'')
- {
- /*
- * Note: if scanner is working right, unescaped quotes can
- * only appear in pairs, so there should be another character.
- */
- i++;
- newStr[j] = s[i];
- }
- else if (s[i] == '\\')
- {
- i++;
- switch (s[i])
- {
- case 'b':
- newStr[j] = '\b';
- break;
- case 'f':
- newStr[j] = '\f';
- break;
- case 'n':
- newStr[j] = '\n';
- break;
- case 'r':
- newStr[j] = '\r';
- break;
- case 't':
- newStr[j] = '\t';
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- {
- int k;
- long octVal = 0;
-
- for (k = 0;
- s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
- k++)
- octVal = (octVal << 3) + (s[i + k] - '0');
- i += k - 1;
- newStr[j] = ((char) octVal);
- }
- break;
- default:
- newStr[j] = s[i];
- break;
- } /* switch */
- } /* s[i] == '\\' */
- else
- newStr[j] = s[i];
- j++;
- }
- newStr[j] = '\0';
- return newStr;
-}