@@ -26,7 +26,7 @@ use warnings;
2626use Carp;
2727use DBI;
2828use Getopt::Long qw/ GetOptions :config no_ignore_case / ;
29- use Test::More tests => 14 ;
29+ use Test::More tests => 15 ;
3030
3131$| = 1;
3232
@@ -191,6 +191,60 @@ $dbh->do(qq{
191191} );
192192
193193
194+ # ## Long identifier
195+
196+ # We construct a temporary table name based on the combination
197+ # of the schema and table. That was exceeding the maximum identifier
198+ # length in some cases. We're now truncating the temporary table
199+ # names when necessary.
200+
201+ my $maxlen = 63;
202+ eval {
203+ my $config = $dbh -> selectrow_hashref(q{
204+ SELECT current_setting('max_identifier_length') AS namedatalen
205+ } );
206+ $config //= {};
207+ $maxlen = $config -> {namedatalen } // $maxlen ;
208+ };
209+ if ($@ ) {
210+ diag(" Unable to determine max identifer length: $@ " );
211+ diag(" Defaulting to max identifier length of '$maxlen '" );
212+ } else {
213+ diag(" Max identifier length: $maxlen " );
214+ }
215+
216+ my $long_schema = ' long_schema_' . (' X' x $maxlen );
217+ $long_schema = substr $long_schema , 0, $maxlen ;
218+ $dbh -> do(" CREATE SCHEMA $long_schema " );
219+
220+ my $long_name = ' long_name_' . (' X' x $maxlen );
221+ $long_name = substr $long_name , 0, $maxlen - 1;
222+ $long_name .= ' 1' ;
223+
224+ $dbh -> do(qq{
225+ CREATE TABLE $long_schema .$long_name (
226+ id int PRIMARY KEY
227+ );
228+ } );
229+ for (1..10) {
230+ $dbh -> do(" INSERT INTO $long_schema .$long_name (id) VALUES ($_ )" );
231+ }
232+
233+ $dbh -> do(qq{
234+ CREATE TABLE $long_schema .child (
235+ id int PRIMARY KEY
236+ ,parent_id int NOT NULL REFERENCES $long_schema .$long_name
237+ );
238+ } );
239+ for (1..10) {
240+ $dbh -> do(" INSERT INTO $long_schema .child (id, parent_id) VALUES ($_ , $_ )" );
241+ }
242+
243+
244+ # ## End long identifier
245+
246+
247+
194248# ## Partitioning
195249
196250eval {
@@ -257,6 +311,11 @@ is($row->{name}, "\\.", "escaping");
257311my ($ord ) = $dbh -> selectrow_array(qq{ SELECT STRING_AGG(id::text, ',') FROM "test_ordered" GROUP BY TRUE } );
258312is($ord , ' 2,1' , " ordered test case broken, this should return by clustered order" );
259313
314+ ($cnt ) = $dbh -> selectrow_array(" SELECT count(*) FROM $long_schema .$long_name " );
315+ is($cnt , 10, " long table name should have 10 rows" );
316+
317+
318+
260319@opts = (' --ordered' );
261320push @opts , ' --verbose' if $opt {verbose };
262321$cmd = " pg_sample @opts $opt {db_name} > sample_ordered.sql" ;
0 commit comments